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

How do you make something hurt the player who touches it?

Asked by
wjs3456 90
9 years ago

Sort of embarrassing but I'm lost. I'm trying to figure out how to make a brick hurt whoever touches it but I don't know the word. To access the humanoid health I used:

Health=game.Players.player.Humanoid.Health but it said player is not a child of Players

0
You can not Minus rep random people, for a start. unix_system 55 — 9y

1 answer

Log in to vote
0
Answered by
Seraine 103
9 years ago
function onTouch(part) 
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    if (humanoid ~= nil) then   -- if a humanoid exists, then
        humanoid.Health = 0 -- "0" kills the player, you can change how much the brick damages the player.
    end 
end

script.Parent.Touched:connect(onTouch)

Hope it helps !

0
Um, I'd change line 4 because then it'll automaticly kill the player, try 'humanoid.Health=humanoid.Health-Damage' TheeDeathCaster 2368 — 9y
Ad

Answer this question