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

This GUI kill button doesn't work please help?

local Kill = script.Parent
function onClicked (MouseButton1Down)
	local Player = game.StarterGui.TextBox:FindFirstChild("Humanoid")
	if (Player ~=nil) then do
		Player.Health = 0
	end
	end
	TextBox.Touched:connect(onClicked)

2 answers

✓ Accepted answer

Before anything, you would not use a TextBox for this, but rather use a TextButton. Using a LocalScript inside the TextButton, the code would look a bit like this:

Player = game.Players.LocalPlayer
Character = Player.Character

KillButton = script.Parent

KillButton.MouseButton1Click:connect(function()
	local Humanoid = Character:FindFirstChild("Humanoid")
	if (Humanoid) then
		Character.Humanoid:TakeDamage(Character.Humanoid.MaxHealth)
	end
end)

Where is TextBox defined? Did you mean to make TextBox Kill? If TextBox(or Kill) is the kill button, you need to make it MouseButton1Click. Also, you put if(Player) then do, I'm guessing that was a typo.

Possible Fix:

local KillButton=script.Parent;
function onClicked()
	local Player = game.StarterGui.TextBox:FindFirstChild("Humanoid");
	if (Player) then
		Player.Health=0;
	end;
end;

KillButton.MouseButton1Click:connect(onClicked);

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