Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does the bullet from my turret not kill?

I have a turret that fires a part. I want this part to kill the person it touches, but it does not kill. The turret DOES fire the part, but it does not KILL. Please help

gun = script.Parent
gunPos= gun.Position

function firePart()
	local part = Instance.new("Part",workspace)
	part.Size = Vector3.new(1,1,1)
	part.Material = "SmoothPlastic"
	part.Position = gunPos
	part.Velocity = Vector3.new(0,0,-150)
end
wait(3.2)
while true do
	firePart()
	wait(0.2)
	firePart()
	wait(0.2)
end

local part = Instance.new("Part",workspace)

script.Parent.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
	end
end)

1 comment

0

Did you check that the part is actually hitting the player?

1 answer

✓ Accepted answer

The problem here is that you are detecting if the scripts' parent (the gun) is hitting something, you should do this instead

gun = script.Parent
gunPos= gun.Position

function firePart()
    local part = Instance.new("Part",workspace)
    part.Size = Vector3.new(1,1,1)
    part.Material = "SmoothPlastic"
    part.Position = gunPos
    part.Velocity = Vector3.new(0,0,-150)
    part.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
	    hit.Parent.Humanoid.Health = 0
	end
    end)
end

wait(3.2)

while true do
    firePart()
    wait(0.2)
    firePart()
    wait(0.2)
end

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.