Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Will this gun script work?

Asked by
IcyEvil 260 Moderation Voter
10 years ago

Trying to learn to script guns, so I decided I would try and make one using part of the wikis script and some of my coding.

local tool = script.Parent
local user
user = tool.Parent
tool.Equiped:connect(function(mouse)
      missile = Instance.new("Part")
missile.Name = "Bullet"
missile.Shape = "Block"
missile.Anchored = false
missile.CanCollide = true
missile.CFrame = handle.CFrame
missile.Size = Vector3.new(1, 1.2, 7)
missile.BrickColor = BrickColor.new("Really black")  --when the left mouse button is clicked
   mouse.Button1Down:connect(function() 
       --make and do a hit test along the ray
       local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300)
       local hit, position = game.Workspace:FindPartOnRay(ray, user)

       --do damage to any humanoids hit
       local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
       if humanoid then
           humanoid:TakeDamage(10)
       end
end)
end)

0
You never use the bullet you created. 'user' should not be defined until the tool is equipped, because otherwise it won't equal the character. It is also much cleaner to create the bullet in a separate function. Perci1 4988 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

Why are you even asking this question? You have to test it your self then if it does not work, then post this here!

Ad

Answer this question