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

Not killing player that touches?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago
Text = "Test"

script.Parent.Touched:connect(function(Player)
local hum = Player.Parent:FindFirstChild("Humanoid")
    hum.Health = 0
print(Text)
end)

2 answers

Log in to vote
2
Answered by 8 years ago
Text = "Test"

script.Parent.Touched:connect(function(Player)
    local hum = Player.Parent:FindFirstChild("Humanoid")
    if hum then
        hum.Health = 0
    end
    print(Text)
end)

You were using FindFirstChild wrong. You had the right idea though. But you weren't checking if it found the humanoid you were just searching for it and regardless of the result you used it in the script.

FindFirstChild returns nil if it can't find the child you're looking for, otherwise it returns the child

0
Does not work FiredDusk 1466 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

An easier way to do this too is by making a WaitForChild.

Text = "Test"
script.Parent.Touched:connect(function(hit)
    local hum = hit.Parent:WaitForChild("Humanoid")
    if hum then 
        hum.Health = 0
        print(Text)
    end
end)

Unlike FindFirstChild, this will wait for the child to exist, then set "hum" as the player's humanoid.

Answer this question