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

My gun's bullets arent launching and it doesnt damage npcs?

Asked by 5 years ago

hi. I am trying to make a gun and it doesnt really work.


script.Parent.Parent.Activated:Connect(function() wait(.5) local part = Instance.new("Part",workspace) part.Size = Vector3.new(.5,.5,.5) part.BrickColor = BrickColor.new(255,255,0) part.Transparency = 0 part.CanCollide = false part.Position = script.Parent.Position + Vector3.new(-10,0,0) wait(.5) local originalposition = part.Position while wait(.5) do part.Velocity = part.Velocity + Vector3.new(12,12,12) end part.Touched:Connect(function(hit) local h = hit.Parent:WaitForChild("Humanoid") if h ~= nil then wait(.5) h:TakeDamage(30) end end) end)

when i use it the bullet doesnt even get launched it just spawns and falls on the floor and when the bullet hits a npc it doesnt get damaged. Help? :)

1 answer

Log in to vote
3
Answered by 5 years ago

It may be beneficial to not use a physical object for this. If you wish to add a bullet for animation reasons, then I recommend using tweening and a very slow period. However, for your gun itself, it would be much smarted to use ray casting. Blocks take up an okay chunk of work to do ( imaging if a game full of people were shooting, you could have hundreds of fast moving blocks with scripts ).

Using recasting, you can easily determine is the bullet will hit somebody, figure out who, preform all calculations ahead of time, and instead use a bullet purely for animation reasons. I've had poor experience for the touched event.

You can find a tutorial by Roblox here, which'll show you how to make a ray gun, that implements raycasting. Once you get the hang of it, you can replace the code with your current system, and possibly add a bullet that travels from A to B.

https://developer.roblox.com/articles/Making-a-ray-casting-laser-gun-in-Roblox

0
ok thanks!! nzsalty16 81 — 5y
Ad

Answer this question