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

Help. I do not know what I am doing wrong with the most simple PlayerGui button?

This is an example code:

function Play()
	Print("Bruh")
end


game.Players.LocalPlayer.PlayerGui.ScreenGui.Button.MouseButton1Click:Connect(Play)

I don't know what I'm doing wrong, when I press the button nothing happens, and I need to get my mouse off of the button before I can click it again.

1 comment

0

It was working fine before but maybe roblox updates made it broke.

2 answers

✓ Accepted answer

Make sure it's a local script and you can just put the local script inside the button then do

local button = script.Parent--finds the button easily without having to start at game.Players

function announce()
print("Bruh")
end

button.MouseButton1Click:Connect(function()
announce()
end)

do you get any errors? if yes then tell us, try this

function Play()
    Print("Bruh")
end


game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("Button").MouseButton1Click:Connect(Play)

the function :WaitForChild("Child name") will wait untill the object is loaded, because if it try to find it but the object is not there then it will error. Also make sure that it is a local script.

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