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

How do I make a click detector kill the player?

Asked by 5 years ago

What is wrong with this script? I want it to kill the player who clicks it. I put this on a script inside of the click detector.

script.Parent.MouseClick:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        hit.Parent:FindFirstChild('Humanoid').Health = 0
    end
end)

2 answers

Log in to vote
0
Answered by
clc02 553 Moderation Voter
5 years ago

MouseClick passes the player that clicks it, not a part. You'll want to use hit.Character.Humanoid, and probably rename hit to player to avoid confusion later down the line.

0
I thought that MouseClick passed the mouse? stef0206 125 — 5y
0
Nope! https://developer.roblox.com/api-reference/class/ClickDetector you can see it under events, passes the player clc02 553 — 5y
0
Thanks, it worked. DuckOffender 6 — 5y
Ad
Log in to vote
0
Answered by
stef0206 125
5 years ago

Im not 100% sure, but i believe hit would be a child of the player, not the character, try script.Parent.MouseClick:Connect(function(hit) 2 if hit.Parent.Character:FindFirstChild('Humanoid') then 3 hit.Parent.Character:FindFirstChild('Humanoid').Health = 0 4 end 5 end)

0
Oh well lol stef0206 125 — 5y
0
https://developer.roblox.com/api-reference/class/ClickDetector MouseClick passes the player when used with ClickDetectors clc02 553 — 5y
1
also in the future, try putting your code in code blocks theking48989987 2147 — 5y
0
Yeah i just joined the website when i wrote this stef0206 125 — 5y

Answer this question