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

Player killing preventing?

This kills the player when the part that shoots hits the player that has the gun.

Part.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5
Part:Destroy()
else
if hit.Name == "Head" then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5 *1.25
Part:Destroy()
end
end
end)

3 comments

1

wait what? I don't see what you're trying to accomplish type in what you need help with or you want the script to do showing us a script and giving us barely anything telling us what you want isn't going to help

0

This makes no sence ._.

0

Well when the bullet shoots and the players arm is in the way it hurts the player. Trying to figure out how to ignore it.

1 answer

Add an "owner" variable to signify the creator of the part.(player that shot the gun) This variable must be created and set earlier in the script.

Part.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent.Name == owner.Name then
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5
		Part:Destroy()
	else
		if hit.Name == "Head" and not hit.Parent.Name == owner.Name then
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5 *1.25
			Part:Destroy()
		end
	end
end)

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