Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a ScreenGui frame Visible while another is not Visible?

So basically When I load up the game, I want only the Menu Frame to be Visible. And when I press the Play button, I want the Teams Frame to be Visible and the Menu Frame to be not Visible. But when I load up the game, Both of the Frames are Visible and pressing the play Button and the Samurai Button does nothing

local MenuGui = game.StarterGui.MenuGui
local MenuFrame = MenuGui.MenuFrame
local TeamsFrame = MenuGui.TeamsFrame
local Player = game.Players.LocalPlayer

game.StarterGui.MenuGui.Enabled = true
game.StarterGui.MenuGui.MenuFrame.Visible = true
game.StarterGui.MenuGui.TeamsFrame.Visible = false

--Play Button
MenuFrame.PlayButton.MouseButton1Click:Connect(function()
	MenuFrame.Visible = false
	TeamsFrame.Visible = true
end)

--Samurai Button
TeamsFrame.SamuraiButton.MouseButton1Click:Connect(function()
	Player.Team = game.Teams.Samurai
	Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(237, 8, -176))
	MenuGui.Enabled = false
end)

--[[
StarterGui
  -Main LocalScript --What is above
  -MenuFrame
	-PlayButton
  -TeamsFrame
	-SamuraiButton
]]

1 answer

✓ Accepted answer

The problem is, you are editing the gui in StarterGui, not the PlayerGui. StarterGui is where guis are stored for players who join or get respawned. As a result, you are just changing what a new player would see, not what the current player sees.

Try this code out:

local Player = game.Players.LocalPlayer
local MenuGui = Player.PlayerGui.MenuGui
local MenuFrame = MenuGui.MenuFrame
local TeamsFrame = MenuGui.TeamsFrame

MenuGui.Enabled = true
MenuGui.MenuFrame.Visible = true
MenuGui.TeamsFrame.Visible = false

--Play Button
MenuFrame.PlayButton.MouseButton1Click:Connect(function()
    MenuFrame.Visible = false
    TeamsFrame.Visible = true
end)

--Samurai Button
TeamsFrame.SamuraiButton.MouseButton1Click:Connect(function()
    Player.Team = game.Teams.Samurai
    Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(237, 8, -176))
    MenuGui.Enabled = false
end)

1 comment

0

Thank You Sooo Much!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.