So basically I wanted to make a script for a button(or more accurately, clickable part/brick) that kills the player whenever they click on it. However, my script doesn't work at all, and it doesn't seem to be showing any errors or warnings. I can still click on the button though, it just doesn't do anything.
This is the script:
local deathbutton = game.Workspace.DeathButton -- declares local variable for deathbutton(button that will kill player on click) deathbutton.ClickDetector.MouseClick:Connect(function(plr) -- Connects click event to the function if plr:FindFirstChild("Humanoid") then -- checks if humanoid exists in player plr.Health = 0 -- if so, player's health is set to 0 end end)
I'm fairly new to scripting, so if anybody could point out the mistake in my code, I'd be grateful
Local script in StarterGui:
local b = workspace.DeathButton.ClickDetector b.MouseClick:Connect(function() local plr = game.Players.LocalPlayer plr.Character.Humanoid:TakeDamage(100) local bn = Instance.new("ClickDetector") bn.Parent = b.Parent b:Destroy() end)
If this helped please up vote and accept this answer.
All the best,
PrismaticFruits