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

Can you help me with a script?

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

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)

3 comments

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 ''

0

oops sorry, forgot a parenthesis on the last end, the code should work now

0

It works! Thank you very much :)

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