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

Killing a player though Gui Buttons?

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

✓ Accepted answer
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

script.Parent.MouseButton1Click:Connect(function()
	char:BreakJoints()
end)

1 comment

0

Cool Thanks!

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

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