How do you switch GUI to invisible when a player joins?

Hello there,
I am trying to figure out how to make my GUI disappear after a certain amount of time after a player joins the game(let’s say 10 seconds). Not the entire GUI system but only certain components such as frames and buttons as I list in my main code down below. I tried using the “OnPlayerAdded” function but it does not seem to work. So Instead of throwing all my code in, I used the bare basics and I just tried doing a print statement. However, even the print statement did not want to work:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " joined the game!")
end)

My main Code looks like this:

local Players = game:GetService("Players")


-- [GETTING ALL THE TUTORIAL BUTTONS]--
local AnimTut = script.Parent.Main.HUD.RightSide.Animations.Tutorial
local AviTut = script.Parent.Main.HUD.RightSide.AvatarEditor.Tutorial
local BackTut = script.Parent.Main.HUD.RightSide.Backpack.Tutorial
local CarTut = script.Parent.Main.HUD.RightSide.Cars.Tutorial
local PlotTut = script.Parent.Main.HUD.RightSide.PlotSelector.Tutorial



Players.PlayerAdded:Connect(function(player)
	wait(10)
	AnimTut.Visible = false
	AviTut.Visible = false
	BackTut.Visible = false
	CarTut.Visible = false
	PlotTut.Visible = false
end)

All of the code is in a server-side script at the moment, I did try putting it into LocalScripts however I got the same results, I then tried throwing the code into “ServerScriptService” Since the code is currently in the “StarterGUI” Category. However, as I said earlier nothing seems to work. Is there any way to make this happen?

Help much Appreciated :slightly_smiling_face:

Look for the Main GUI, that’s holding everything.
image
Then, do

image

Or Enabled = false

1 Like

Hi, I think I gave off the wrong explanation of what I am trying to do. I am only trying to turn off certain GUI components such as frames within the GUI, not the entire GUI itself. As you can see in the main code listed above. Thank you for your help though!

1 Like

In a local script in StarterPlayerScripts so it runs when the player joins:

local function usesVisible(gui)
	local success, result = pcall(function()
		gui.Visible = gui.Visible
	end)

	return success
end


local guiToHide = {} -- Table of guis you want to hide

local HIDE_AFTER_AMOUNT = 10


task.wait(HIDE_AFTER_AMOUNT)

for _, gui in pairs(guiToHide) do
	if usesVisible(gui) then
		gui.Visible = false
	else
		gui.Enabled = false
	end
end
2 Likes

Hello, the reason your code isn’t working is because all children of StarterGui are put into a folder called PlayerGui.

Here is a fix to your code:

local Players = game:GetService("Players")


-- [GETTING ALL THE TUTORIAL BUTTONS]--
local AnimTut = script.Parent.Main.HUD.RightSide.Animations.Tutorial
local AviTut = script.Parent.Main.HUD.RightSide.AvatarEditor.Tutorial
local BackTut = script.Parent.Main.HUD.RightSide.Backpack.Tutorial
local CarTut = script.Parent.Main.HUD.RightSide.Cars.Tutorial
local PlotTut = script.Parent.Main.HUD.RightSide.PlotSelector.Tutorial

wait(10)
AnimTut.Visible = false
AviTut.Visible = false
BackTut.Visible = false
CarTut.Visible = false
PlotTut.Visible = false

The reason your print statement probably didn’t work was because it was in a LocalScript or a client folder.

Please remember to give this a like and mark this as a solution if it helped.

1 Like

So no one actually gave the real reason, the issue is that the “PlayerAdded” event does not fire in local scripts, as it isn’t necessary for it to do so, the client’s player instance (for which the local script is executing for) can easily be fetched by indexing the “LocalPlayer” property of the player’s service. As such, the scripts you provided would work as local scripts if rewritten as the following.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
print(Player.Name .. " joined the game!")
local RightSide = script.Parent.Main.HUD.RightSide
local AnimTut = RightSide.Animations.Tutorial
local AviTut = RightSide.AvatarEditor.Tutorial
local BackTut = RightSide.Backpack.Tutorial
local CarTut = RightSide.Cars.Tutorial
local PlotTut = RightSide.PlotSelector.Tutorial
task.wait(10)
AnimTut.Visible = false
AviTut.Visible = false
BackTut.Visible = false
CarTut.Visible = false
PlotTut.Visible = false

With a little cleaning up on the second script too.

1 Like

Thank you very much for the feedback! :slightly_smiling_face: