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

Player killing preventing?

Asked by 9 years ago

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)
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 Prioxis 673 — 9y
0
This makes no sence ._. MessorAdmin 598 — 9y
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. ScriptingCon 52 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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)
Ad

Answer this question