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

Can you help me with a script?

Asked by
0User 0
9 years ago

Hello,

I was trying this for over an hour, tried youtube vids, the wiki, and google. Im trying to make a GUI button that kills you when you click it. I have the gui and everything, but I want to know how the script would go.

This is what i was trying:

Button.MouseButton1Down:connect function()

game.Player.Humanoid.Health = 0

end

Im not a great scripter, still learning, but just asking for a little help with this certain script.

1 answer

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
9 years ago

Make sure the gui you are working on has the .MouseButton1Down event. (imagebutton, textbutton, etc..) Also in your code you need to access the character from the localplayer.

local player = game.Players.LocalPlayer

local character = player.Character

local humanoid = character.Humanoid

If you wanted to click the gui and have it kill your character, you're better off with the .MouseButton1Click event

Make this a localscript and parent it in the gui object

local player = game:GetService'Players'.LocalPlayer
local gui = script.Parent
repeat wait() until player.Character
local character = player.Character

gui.MouseButton1Down:connect(function()
    local humanoid = character:FindFirstChild'Humanoid'
    if humanoid then
    humanoid.Health = 0
    end
end)

0
When I try executing the script, it gives me this error in the output: 00:48:01.520 - Players.Player.PlayerGui.ScreenGui.Box.Sucide.LocalScript:15: ')' expected (to close '(' at line 6) near '<eof>' 0User 0 — 9y
0
oops sorry, forgot a parenthesis on the last end, the code should work now 4Bros 550 — 9y
0
It works! Thank you very much :) 0User 0 — 9y
Ad

Answer this question