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

How do i kill the player using ClickDetector?

Asked by 1 year ago

So ive been trying to make a part kill you using clickdetector by myself first, but all my attempts were unusuccesful

local players = game:GetService("Players")
local ClickDetector = game.Workspace.clickpart.ClickDetector
local clickpart = script.Parent

clickpart.ClickDetector.MouseClick:Connect(function(hit)
    local player = players:GetPlayerFromCharacter(hit.Parent)
    if player then
        local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")

        if humanoid.Health > 0 then
            humanoid.Health = 0
        end
    end
end)

1 answer

Log in to vote
1
Answered by 1 year ago

Your mistake is in line 6. 'Hit' is actually Player, so you don't need line 6.

This should work:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    plr.Character:FindFirstChild("Humanoid").Health = 0     
end)
0
dude i never thought it would be that simple with just 3 lines of code, thank you Artemiygogolev 23 — 1y
Ad

Answer this question