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

Does this code kill a Humanoid?

Asked by 4 years ago

script.Parent.Touched:Connect(function(hit) if hit and hit.Parent.FindFirstChild("Humanoid")then hit.Parent.Humanoid.Health = 0 end
end)

i need help with this code because when i jump on it, it doesnt kill me

0
Where is the script located? M39a9am3R 3210 — 4y
0
it is located right under the part so the part is the 'Parent' iikinqi1 5 — 4y
0
I mean you could test it The_Pr0fessor 595 — 4y
0
i did and im not dying iikinqi1 5 — 4y
View all comments (2 more)
1
So no... The_Pr0fessor 595 — 4y
0
Try and remove the 'If Hit and' part Fad99 286 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

Just an add on to the above but explaining a little more about which does what

script.Parent.Touched:Connect(function(hit) --connect a function to when the block is touched

local humanoidcheck = hit.Parent:FindFirstChild("Humanoid") --make sure this is a player and not some random object

if humanoidcheck ~= nil then --if humanoid is not equal to nil (non existing) then

humanoidcheck.Health = 0 --kill the player

end

end)
Ad
Log in to vote
0
Answered by
Psudar 882 Moderation Voter
4 years ago
Edited 4 years ago

```lua script.Parent.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid")then

    hit.Parent.Humanoid.Health = 0

 end

end) ```

You just had a slight error in where you placed the " : " on :FindFirstChild(). You probably had something like, "FindFirstChild is not a member of hit" in your errors output.

No problem.

Answer this question