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

How do I make my damage script damage everyone else except me?

Asked by 6 years ago

Hi, I have this damage script I made and it works, but it also damages my self.

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid")~= nil then
    hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
        script.Parent:remove()

    end

end)

How would I go about fixing this issue? Any help would be appreciated. -A newbie Scripter

1 answer

Log in to vote
0
Answered by 6 years ago
script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if hit.Parent:FindFirstChild("Humanoid")~= nil and player.UserID ~= 00000 then
     -- change 00000 with your id
    hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
        script.Parent:remove()
    end

end)
end)
0
Stop using deprecated methods. it’s script.Parent:Destroy() and :Connect(), not :connect User#19524 175 — 6y
0
They both work eloiishot 47 — 6y
0
@incap it really dont matter it works either way. TheScriptKing 102 — 6y
Ad

Answer this question