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

How To Fix My Click Detector Activated Kill Script?

I just started scripting and I tried to make a basic click detoctor activated kill script. It doesn't give me any errors but it also doesn't work.

local yesclick = game.workspace.Click_Event_Test.ClickDetector.MouseClick
local Player = game:GetService'Players'.LocalPlayer
local Char = Player.Character

function killself()
	Char.Humanoid.Health = 0
end

yesclick:Connect(killself)

1 comment

0

just do workspace and not game.Workspace

1 answer

First of all, I would put this inside a normal script so that when you die it's replicated to the server (so that other people can see you die as well), with that being said, this is how you could do it (explanations in the script):

-- put this script inside the part that you want to be clicked
-- also put a clickdetector inside the part

local Clicked = script.Parent.ClickDetector.MouseClick

function KillSelf(Player) -- function to kill player (gets the player who clicked)
	if Player.Character:WaitForChild("Humanoid") then -- if players humanoid exists then
		Player.Character.Humanoid.Health = 0 -- kills the player
	end
end

Clicked:Connect(KillSelf) -- when part is clicked function KillSelf runs

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