My script doesnt work

i did make a local script so when you click credits button then credits menu appear but it doesnt work

local CreditsGui = game.StarterGui.Menu.Credits
local CreditsMenu = game.StarterGui.CreditsMenu
local Menu = game.StarterGui.Menu
local Player = game.Players.LocalPlayer

--Make that if you click CreditsGui then Menu is gonna disappear and CreditsMenu is gonna appear
CreditsGui.MouseButton1Click:Connect(function()
    Menu.Enabled = false
    CreditsMenu.Enabled = true
end)

3 Likes

This is your issue. When you are referencing a UI in the LocalPlayer, you need to use PlayerGui, instead of StarterGui. StarterGui is just a place where you put all the UIs and frames and whatnot that will be cloned to each players’ PlayerGui. Therefore, try changing your script to the following:

local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Menu = PlayerGui.Menu
local CreditsGui = Menu.Credits
local CreditsMenu = PlayerGui.CreditsMenu


--Make that if you click CreditsGui then Menu is gonna disappear and CreditsMenu is gonna appear
CreditsGui.MouseButton1Click:Connect(function()
    Menu.Enabled = false
    CreditsMenu.Enabled = true
end)

it says to me that CreditsMenu is not a valid member of PlayerGui “Players.chavalquepro.PlayerGui” but it exists on the player gui tho

Can you send me a screenshot of the StarterGui folder and all the items in it?

AnotaciĂłn 2023-09-24 190106
AnotaciĂłn 2023-09-24 190026

Are you sure you’re getting that error from the same script? From what I can see, that’s an error from a ServerScript you have in your game that is different from the LocalScript you’re using

I think it’s best to use Frame.Visible = false instead of Gui.Enabled = false

It depends on his use case. Unless he intends on having multiple frames in the same UI, there isn’t much of a need.

Yes I know but from the multiple times I tried the script with the frame instead of the gui, it worked with no issues

Why is that? ScreenGui.Enabled can be used.

Whoops, Im blind LOL SO BLIND.

i got this too on the local script

Are you sure the UI is directly under the PlayerGui?
We can try using WaitForChild in case it didn’t load in properly.

local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Menu = PlayerGui:WaitForChild("Menu")
local CreditsMenu = PlayerGui:WaitForChild("CreditsMenu")
local CreditsGui = Menu.Credits

--Make that if you click CreditsGui then Menu is gonna disappear and CreditsMenu is gonna appear
CreditsGui.MouseButton1Click:Connect(function()
    Menu.Enabled = false
    CreditsMenu.Enabled = true
end)

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