How to changes between 5 screengui?

I have a UI, and it have 5 tabs: Home, Games, Customization, Settings, Labs
Im need to change between it with buttons

Screenshot:

I tried write this:

--Module script:
local UIController = {}

function UIController.SwitchTo(To)
	for _,v in pairs(game.StarterGui:GetChildren()) do
		if v.Name ~= 'TopBar' or v.Name ~= 'Chat' then
			if v:IsA("ScreenGui") then
				v.Enabled = false
				if v.Name == To then
					v.Enabled = true
				end
			end
		end
	end
end

return UIController

--Local Script:
local UIController = require(game.StarterGui.UIController)

script.Parent.MouseButton1Click:Connect(function()
	UIController.SwitchTo('HomePage')
end)

Ierarchy:
image

2 Likes

Sorry, I’m kinda of confused what is it you want to accomplish exactly?

I’m confused as well, also whats up with

script.Parent.MouseButton1Click:Connect(function()
	UIController.SwitchTo('HomePage')
end)

script.Parent == startergui / playergui…

also if you want to swap between guis, wouldn’t you just disable or enable targetobjects as needed?

-- Module script:
local UIController = {}

function UIController.SwitchTo(To)
	for _,v in pairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do
		if v.Name ~= 'TopBar' or v.Name ~= 'Chat' then
			if v:IsA("ScreenGui") then
				v.Enabled = false
				if v.Name == To then
					v.Enabled = true
				end
			end
		end
	end
end

return UIController

--Local Script:
local UIController = require(game.StarterGui.UIController)

script.Parent.MouseButton1Click:Connect(function()
	UIController.SwitchTo('HomePage')
end)

Try this one.

You’re trying to edit player’s gui with accessing StarterGui. Nothing in StarterGui is in the player’s screen. StarterGui only cloning Gui into player’s gui.

1 Like

Try this:

-- Module script:
local UIController = {}
local playerGui = game.Players.LocalPlayer.PlayerGui

function UIController.SwitchTo(To)
	for _,v in pairs(playerGui:GetChildren()) do
		if v.Name ~= 'TopBar' or v.Name ~= 'Chat' then
			if v:IsA("ScreenGui") then
				v.Enabled = false
			end
		end
	end
    playerGui[To].Enabled = true
end

return UIController

--Local Script:
local UIController = require(game.Players.LocalPlayer.UIController)

script.Parent.MouseButton1Click:Connect(function()
	UIController.SwitchTo('HomePage')
end)
1 Like

Im wanna switch between GUI’s
Example: Home > Customization, Customization > Settings and etc.

ok, thanks i try it and reply later!

Yep! It’s works! Thanks! I can’t do it 2-3 days, thx!
Hm, TopBar is disables, but shouldn’t

1 Like

HomePage:


Games:

When i change to Games, topbar disables

Is “Games” the correct name of the ScreenGui & a valid ScreenGui?
Edit: Do you mean that TopBar should always be open?

1 Like

Yes, it correct name & valid ScreenGui
image

1 Like

yes, i mean that TopBar should always be open

1 Like
-- Module script:
local UIController = {}
local playerGui = game.Players.LocalPlayer.PlayerGui

function UIController.SwitchTo(To)
	for _,v in pairs(playerGui:GetChildren()) do
		if v.Name ~= 'TopBar' or v.Name ~= 'Chat' then
			if v:IsA("ScreenGui") then
				v.Enabled = false
			end
		end
	end
    playerGui[To].Enabled = true
    playerGui['TopBar'].Enabled = true
end

return UIController

--Local Script:
local UIController = require(game.Players.LocalPlayer.UIController)

script.Parent.MouseButton1Click:Connect(function()
	UIController.SwitchTo('HomePage')
end)
1 Like

oh, it’s be stupid mistake, sry, thanks!

1 Like

Hi, i need to change a button color when player is hover on it, i added in button this:

script.Parent.MouseEnter:Connect(function()
	local tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear) -- Sets up TweenInfo

	local Tween = TweenService:Create(script.Parent, tweenInfo , {BackgroundTransparency = 0, BackgroundColor3 = Color3.fromRGB(0, 81, 255)}) -- Creates the tween
	Tween:Play() -- Plays the tween
end)

script.Parent.MouseLeave:Connect(function()
	local tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear) -- Sets up TweenInfo

	local Tween = TweenService:Create(script.Parent, tweenInfo , {BackgroundTransparency = 0.5, BackgroundColor3 = Color3.fromRGB(0, 0, 0)}) -- Creates the tween
	Tween:Play()
end)

But i need save a button color on active page, how i can do this?

Change the BackgroundColor3 of the button.

i know, and i do it, i need save a blue color on button when page opened

Perhaps save it under an variable/attribute and load it when the player reopens the GUI.

1 Like