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

Killing a player though Gui Buttons?

Asked by 6 years ago

Hey, I need a script so when the player clicks the Button in my gui, the player will die. I'm thinking it would be something like

function OnClicked()
    local humanoid = game.Players.Player
     humanoid = true
    humanoid.Health = 0
end

(What I have so far) If there is any better ways to do the whole click detection, please let me know. Thanks!

2 answers

Log in to vote
0
Answered by 6 years ago
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

script.Parent.MouseButton1Click:Connect(function()
    char:BreakJoints()
end)
0
Cool Thanks! Porkface09 -3 — 6y
Ad
Log in to vote
2
Answered by 6 years ago
function OnClicked()
    local humanoid = game.Players.LocalPlayer.Character.Humanoid
    humanoid.Health = 0
end

script.Parent.MouseButton1Down:Connect(OnClicked)

Problems you had:

1. game.Players.Player is looking for someone in the game named "Player", game.Players.LocalPlayer gets the player that the script is currently running in

2. Players aren't humanoids, you have to do (PLAYER).Character.Humanoid

3. Humanoids aren't values, you can't set them to true or false

4. You didn't have an entrance to your function, script.Parent.MouseButton1Down:Connect(OnClicked) waits for the button the script is inside to be clicked, then runs the function

Answer this question