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

This GUI kill button doesn't work please help?

Asked by
exit16 20
9 years ago
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

Log in to vote
0
Answered by 9 years ago

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)
Ad
Log in to vote
0
Answered by
Diitto 230 Moderation Voter
9 years ago

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);

Answer this question