Problem with button script

So i’m trying to do a simple button script that makes a white cube gui at the center of the screen visible, but i don’t know why it just doesn’t work

Only the print works, but the part its supposed to make the gui visible just doesn’t shoot, did i do something wrong? i don’t doubt it since i rarely do codes…

Is the ScreenGui disabled by any chance? That would disable anything in the ScreenGui regardless of each instance’s properties. You should go into the explorer and manually turn on the enabled/visible properties for the frame and screengui until it works, then adjust your script accordingly

local button = script.Parent
local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:FindFirstChild("ScreenGui")
local Frame = ScreenGui:FindFirstChild("Frame")

ScreenGui.Enabled = true

local function onButtonClick()
    Frame.Visible = true
end

button.MouseButton1Up:Connect(onButtonClick)

Always make sure to declare the PlayerGui rather than the StarterGui, also no need to place parentheses between the bool that determines the visibility. Lastly don’t use button.Activated as a listener, always use one of these three: button.MouseClick, button.MouseButton1Up, or button.MouseButton1Down

2 Likes

oh it works with no issues! i have seen those button.MouseButton1Up before in some codes, but i didn’t knew it would make a difference

Yeah, I believe button.Activated will listen to any activations so basically and left click or right click.