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?
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!
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
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.