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

Script that I wrote for button doesn't kill the player?

Asked by 4 years ago

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

0
Humanoids are not in the player, they are in the character lol PrismaticFruits 842 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

0
The script worked, thank you so much sir Mathenotics 13 — 4y
Ad

Answer this question