generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: gun script

Previous Thread :: Next Thread 
sgtNElson is not online. sgtNElson
Joined: 23 Oct 2008
Total Posts: 542
12 Apr 2009 10:56 AM
i want to make a meshed pistol that when it runs out of ammo in the clip it says "r to reload i found an assault rifle that dose it but i cant find the reload time an i dont want to to fire rapidly can some one help with this
Report Abuse
sgtNElson is not online. sgtNElson
Joined: 23 Oct 2008
Total Posts: 542
12 Apr 2009 10:59 AM
bump
Report Abuse
sgtNElson is not online. sgtNElson
Joined: 23 Oct 2008
Total Posts: 542
12 Apr 2009 11:00 AM
bump #2
Report Abuse
safenessisgood is not online. safenessisgood
Joined: 16 Mar 2009
Total Posts: 109
12 Apr 2009 11:43 AM
Put a script called "gun script":

originalAmmo = script.Parent.Ammo.Value
m = Instance.new("Message")

function computeDirection(vec)
local lenSquared = vec.magnitude^2
local invSqrt = 1 / math.sqrt(lenSquared)
return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end



function updateAmmo()
m.Text = " "
--for i = 1,script.Parent.Ammo.Value do
-- m.Text = m.Text .. "|"
--end
--for i = 1, (originalAmmo - script.Parent.Ammo.Value) do
-- m.Text = m.Text .. " "
--end
m.Text = m.Text .. " " .. script.Parent.Ammo.Value.. "/12"
end


function fire(v)
for i = 1,1 do
script.Parent.Handle.Fire:play()
script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
updateAmmo()
local dir = v - script.Parent["Handle"].Position
dir = computeDirection(dir)
local pos = script.Parent["Handle"].Position + (dir * 8)
local p = Instance.new("Part")
p.Name = "Projectile"
p.CFrame = CFrame.new(pos, pos + dir)
p.BrickColor = BrickColor.new(24)
p.Reflectance = 0.1
p.Velocity = (script.Parent.Parent["Head"].Position - v).unit * -150
p.Size = Vector3.new(1, 0.4, 1)
p.formFactor = 2
local mesh = script.Parent.Mesh:clone()
mesh.Parent = p
local upforce = Instance.new("BodyForce")
upforce.force = Vector3.new(0, p:GetMass() * 196, 0)
upforce.Parent = p
local s = script.Parent["ProjectileScript"]:Clone()
s.Disabled = false
s.Parent = p
p.Parent = game.Workspace
wait(0)
end
end


function onActivated()
if script.Parent.Enabled == true then
--script.Parent.Enabled = false
if script.Parent.Ammo.Value > 0 then
fire(script.Parent.Parent["Humanoid"].TargetPoint)
else
if script.Parent.Clips.Value >= -30000000000000 then
script.Parent.Enabled = false
script.Parent.Handle.Reload:play()
m.Text = "reloading"
for i =1,5 do
wait(5) --Reload Time
m.Text = m.Text .. "."
end
script.Parent.Clips.Value = script.Parent.Clips.Value - 1
script.Parent.Ammo.Value = originalAmmo
updateAmmo()
script.Parent.Enabled = true
else
m.Text = "No more clips!"
end
end
wait(0.11)
--script.Parent.Enabled = true
end
end


function onEquipped()
local p = game.Players:GetChildren()
for i = 1,#p do
if p[i].Character == script.Parent.Parent then
m.Parent = p[i]
end
end
updateAmmo()
end

function onUnequipped()
m.Parent = nil
end


script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
script.Parent.Unequipped:connect(onUnequipped)
Report Abuse
safenessisgood is not online. safenessisgood
Joined: 16 Mar 2009
Total Posts: 109
12 Apr 2009 11:44 AM
And a script called Projectile script:

damage = 50


game:GetService("Debris"):AddItem(script.Parent, 8)





function onTouched(hit)


if hit.Parent:findFirstChild("Humanoid")~=nil then


hit.Parent["Humanoid"]:TakeDamage(damage)


end


wait()


script.Parent:Remove()


end





script.Parent.Touched:connect(onTouched)
Report Abuse
safenessisgood is not online. safenessisgood
Joined: 16 Mar 2009
Total Posts: 109
12 Apr 2009 11:44 AM
Finally make a local Gui....:

local Tool = script.Parent;



enabled = true

function onButton1Down(mouse)

if not enabled then

return

end



enabled = false

mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"



wait(.2)

mouse.Icon = "rbxasset://textures\\GunCursor.png"

enabled = true



end



function onEquippedLocal(mouse)



if mouse == nil then

print("Mouse not found")

return

end



mouse.Icon = "rbxasset://textures\\GunCursor.png"

mouse.Button1Down:connect(function() onButton1Down(mouse) end)

end





Tool.Equipped:connect(onEquippedLocal)

Report Abuse
safenessisgood is not online. safenessisgood
Joined: 16 Mar 2009
Total Posts: 109
12 Apr 2009 11:47 AM
Now you need an Int value called Ammo (change to how mych in clips)
Then another int value called clips (how many clips ammoXClips=Bullets firred)
A file mesh in the tool not the handel :http://www.roblox.com/asset/?id=2697549
The fire sound in the handel: http://www.roblox.com/asset/?id=2920959
And last but not least the reload sound : http://www.roblox.com/asset/?id=2920960
Report Abuse
bladez479 is not online. bladez479
Joined: 20 Mar 2010
Total Posts: 5
22 Dec 2010 08:55 PM
wow thats amazing..... can you teach me how to script because i need some hands on teaching ive tried to learn but my last teacher bailed on me just because he couldnt be bothered......and then i tried the wiki also hopeless but that scripting you wrote down was amazing.....seriously how do you remember all that...just looking at all that LUA scares me......so can you please help me?????????????????????????????????????????
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
22 Dec 2010 08:57 PM
There's a guide in my models.

It's not complete though. Though I have received many positive reviews. I ran an ad for it and 400 people took it.
Report Abuse
codyedmonson is not online. codyedmonson
Joined: 01 May 2011
Total Posts: 1
04 Jun 2011 12:47 AM
Where do i put the int things at in the gunscript or where
Report Abuse
lTrollz is not online. lTrollz
Joined: 31 May 2011
Total Posts: 47
04 Jun 2011 01:54 AM
[ Content Deleted ]
Report Abuse
UttermostExedra is not online. UttermostExedra
Joined: 28 Dec 2009
Total Posts: 2483
04 Jun 2011 03:17 AM
@safe

LOLOLOLOLOL. That's all copied from Stealth Pilot's gun. xD
Report Abuse
docdude2 is not online. docdude2
Joined: 04 Dec 2010
Total Posts: 23
08 Jun 2011 05:54 PM
hey dude the guy that needs help scripting i have some tips.

1: first start to edit other scripts.
2:try and remember them.
3:look on threads that have the most replys with scripts.
4:DO NOT TRY AND MAKE A KO SCRIPT .
5:dont put in any of your places a script that somewhere says "hack" or "virus"
the next one is for the guy that needs a gun that does all that stuff.
6:dont take advice from newblets.

i hope this advice helped
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
08 Jun 2011 05:57 PM
Nice free models bro.
Report Abuse
SgtBakerrr is not online. SgtBakerrr
Joined: 30 Dec 2011
Total Posts: 1
28 Mar 2012 12:06 AM
Look I have the same prob "bro", so just calm down and sombody will help you
Report Abuse
bloxer414 is not online. bloxer414
Joined: 18 Nov 2010
Total Posts: 41
25 May 2012 11:14 PM
It's simple. I learned from a program called "Scratch".
Report Abuse
bloxer414 is not online. bloxer414
Joined: 18 Nov 2010
Total Posts: 41
25 May 2012 11:20 PM
You can have functions, which tell the script what to do, so if you wanted a brick to trn transparent:

OnTouch(Hit)

Transparency=True
(.5)

Which would mean .5 transparency. (.5 transparency is pretty much semi invisible)
Report Abuse
bloxer414 is not online. bloxer414
Joined: 18 Nov 2010
Total Posts: 41
25 May 2012 11:23 PM
Actually, safnessisgood, it is optional if you want the int value with how many clips you have left.
Report Abuse
gunsmith81 is not online. gunsmith81
Joined: 15 May 2012
Total Posts: 1
06 Jun 2012 07:28 PM
are u good at scripting cuz theres tons of fonies
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
06 Jun 2012 07:51 PM
I think I beat everyone by placing this here:

http://wiki.roblox.com/index.php/How_to_Make_a_Raycasting_Lasergun

MrMcAero
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
06 Jun 2012 07:53 PM
Or, if you want ammo, try this, UNTESTED THOUGH

local Ammo=10 --Per clip
local LoadedAmmo=Ammo--DO NOT CHANGE
local Tool = script.Parent --Set a variable for the tool.
local User --Create a nil value for the character which we can't find yet.
Tool.Equipped:connect(function(mouse) --When it's equipped fire a function.
    User = Tool.Parent --Set the User variable to the character of the person using the tool.
    mouse.Button1Down:connect(function() --When the left mouse button is clicked fire a function.
        if Ammo~=0 then
        Ammo=Ammo-1
        local Ray = Ray.new(Tool.Handle.CFrame.p,(mouse.Hit.p-Tool.Handle.CFrame.p).unit*300) --Make a the ray.
        local Hit,Position = game.Workspace:FindPartOnRay(Ray,User) --Check for collisions along the ray.
        if Hit then --If it hits something.
        if Hit.Parent:FindFirstChild("Humanoid") then --If the thing the ray hit has a humanoid.
            Hit.Parent.Humanoid:TakeDamage(30) --Do 30 damage if they don't have a forcefield.
        end --End the humanoid check.
    end --End the hit check.
        local RayPart = Instance.new("Part",User) --Create a part in the user.
    RayPart.Name = "RayPart" --Set its name.
    RayPart.BrickColor = BrickColor.new("Bright red") --Set its color.
    RayPart.Transparency = 0.5 --Set its transparency.
    RayPart.Anchored = true --Set whether it will fall or not.
    RayPart.CanCollide = false --Set whether people can walk though it or not.
    RayPart.TopSurface = Enum.SurfaceType.Smooth --Make it smooth on the top.
    RayPart.BottomSurface = Enum.SurfaceType.Smooth --Make it smooth on the bottom.
    RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small.
    local Distance = (Position-Tool.Handle.CFrame.p).magnitude --Find the distance between the click and the gun.
    RayPart.Size = Vector3.new(0.2,0.2,Distance) --Set its size to the distance.
    RayPart.CFrame = CFrame.new(Position,Tool.Handle.CFrame.p) * CFrame.new(0,0,-Distance/2) --Move it halfway.
    game.Debris:AddItem(RayPart,0.1) --Add it to the debris.
        end
    end)
    mouse.KeyDown:connect(function(key)
    key=key:lower()
    if key=="r" then
    Ammo=LoadedAmmo
    end
    end)
end)

MrMcAero
Report Abuse
CM901rocks is not online. CM901rocks
Joined: 28 Feb 2012
Total Posts: 73
15 Jun 2012 05:48 PM
gosh scipting gives me headaches. i want to make my own guns but i dont know how to size them of make them work. i made an awesome pistol but its huge. i cant figure out how to do anything with gun making. can anyone like script any guns i ever make?
Report Abuse
DarkAssassin08 is not online. DarkAssassin08
Joined: 06 Aug 2012
Total Posts: 1
17 Sep 2012 02:47 AM
i want a pistol that works and it has infinite ammo just for roleplay.
Report Abuse
Hazania is not online. Hazania
Joined: 04 Jun 2010
Total Posts: 1344
27 Oct 2012 03:44 AM
Ever heard of minimaping? Thats how you make the gun small. Or you just build the gun small in the first place...
Report Abuse
LordSurReal is not online. LordSurReal
Joined: 26 Oct 2013
Total Posts: 4
30 Dec 2013 06:04 PM
That's cool.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image