Help scripting GUI opener

Right now I’m working on a gui score menu for my game. I am scripting the actual opener for the menu.

Say you opened the score menu, and are looking for your statistics for the candy land map(just made that up). Once you find the button to access the statistics, you click it, and brings you to it(its a different frame). After you looked at your statistics for the candy land map, you click the opener(instead of the back button) and the statistics disappear. You re-click the score opener, and it brings you to the candy land map statistics, where you left off.

My problem is it seems as though the main menu wont even appear, even though its properties says its visible and enabled. Even the script says in the output its visible:

local tweenService = game:GetService("TweenService")
local scores = starterGui:WaitForChild("Scores")

local mainMenu = scores.MainMenu
local debounce = false


local function findVisible()
	for i,v in pairs(scores:GetChildren()) do
		if v:IsA("ImageLabel") and v.Visible == true then
			print(v.Name) -- prints what frame is visible
			return v
		end
	end
end

script.Parent.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		if scores.Enabled == false then
			scores.Enabled = true
			local currentMenu = findVisible()
			currentMenu:TweenPosition(UDim2.new(0.3, 0,0.125, 0), "Out", "Quint", 0.75,true)
			wait(0.75)
			debounce = false
		elseif scores.Enabled == true then
			local currentMenu = findVisible()
			currentMenu:TweenPosition(UDim2.new(0.3,0,1.5, 0), "Out", "Quint", 0.75,true)
			wait(0.75)
			debounce = false
	  	    scores.Enabled = false
		end
	end
end)

--{0.3, 0},{0.125, 0}

I have picture of it too:

If you cant read my horrible writing, the output says its visible, its properties says its visible, and its in the correct position. Its Enabled too:

The reason why I didn’t file this as a bug was because I just wanna check and see if anyone can point out any errors in this script. There is nothing in front of the frame, and I have no plugins.

Have a great day! :grinning:

3 Likes

You must enable from the player gui container, a child of the LocalPlayer. enabling it from starter gui will not work gametime because the starter gui gets replicated into the player gui object upon spawning.

1 Like

Yeah, what Si_SenonTN said do you need to do. What you want to do is replace all of the lines with “starterGui” with “game.Players.LocalPlayer.PlayerGui”, or even cleaner: Make some new variables:

Old Code:

local tweenService = game:GetService("TweenService")
local scores = starterGui:WaitForChild("Scores") 

local mainMenu = scores.MainMenu
local debounce = false

New Code:

local tweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer -- Sets the player
local playerGui = player.PlayerGui -- Sets the players PlayerGui
local scores = playerGui:WaitForChild("Scores")  -- We replaced "starterGui" with "playerGui" here.

local mainMenu = scores.MainMenu
local debounce = false

To replace all of the “starterGui” with “playerGui” simply type: ctrl + h, then you should get this screen:
image
If you got that screen, type at Find “starterGui” and at Replace “playerGui”, then click on the second icon:
image

2 Likes