Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i kill the player using ClickDetector?

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

✓ Accepted answer

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)

1 comment

0

dude i never thought it would be that simple with just 3 lines of code, thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.