Issue With UI Button?

Hello.

This is my 3rd and final issue Involving my UI not working.

I am not sure if Roblox is broke, or if I have completely forgotten how to code, but the way I’ve always made UI is NOT working.

Here’s the proof:

And here’s the Code:

local Button = script.Parent
local Frame = game.StarterGui.ScreenGui.Frame

Button.MouseButton1Click:Connect(function()
    Frame.Visible = true
end)

Help is needed greatly. And also much appreciated.

You’re referencing and modifying a GUI through StarterGui, and not the PlayerGui. Whenever a player joins the game, all descendants of StarterGui are cloned and parented into PlayerGui. When scripting GUI for a player, you must always script their PlayerGui. You can reference this hierarchy from a local script as such:

local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

Edit: Your use case would look something like this:

local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local Button = script.Parent
local Frame = playerGui.ScreenGui.Frame

Button.MouseButton1Click:Connect(function()
    Frame.Visible = true
end)
2 Likes

Thank You so much.

I’m extremely new to scripting in Roblox Studio, but you probably could tell that, lol.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.