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

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

Asked by 3 years ago

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.

0
It was working fine before but maybe roblox updates made it broke. GAMER_64T 32 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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)
Ad
Log in to vote
0
Answered by 3 years ago

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.

Answer this question