PlayerAdded event (NOT WORKING)

Hi Everyone, I just want to know I am trying to make a GUI visible when a player joins the game.

But, it won’t work. I tried everything and it still won’t work.

=9-0- pictuter

If im doing something wrong plz tell me. :grinning: :grinning: :grinning: :grinning:

From what I know the local script will run after the event can be cached.

You don’t have to use a PlayerAdded event since local scripts run when the player joins anyway

1 Like

You’d have to do this:

local Players = game.Players
local Player = Players.LocalPlayer

    Player.PlayerGui.ScreenGui.StarterFrame.Frame.Visible = true


    Player.PlayerGui.ScreenGui.StarterFrame.Frame.Visible = false

You can just have the code without PlayerAdded event.

@dandcx correctly identified the answer that you don’t really need a PlayerAdded since localscripts run when the client joins. But I want to point some other things with your code

  • You’re using StarterGui instead of the PlayerGui, just use script.Parent.Visible in this case
  • Use game:GetService("Players") so as it’s the more recommended version as game.Players can have a chance of erroring if the name of the Players service is different

You only really need the visible changing code, so just this

local frame = script.Parent

frame.Visible = true
frame.Visible = false

No need for the other stuff as this will run when the client joins the game

@Kon_Cyerthedeer Use what I had done, simplest way of doing what you need as it still wont work cause you’re referencing StarterGui instead of the Guis in the player


So you want me to do it like this.

Yes but also do what @EmbatTheHybrid said. Define the ui through player gui not startergui

local player = game.Players.LocalPlayer
local PGui = player.PlayerGui
local Gui = PGui:WaitForChild("ScreenGui") 
Gui.ScreenGui.StarterFrame.Visible = true
Gui.ScreenGui.StarterFrame.Visible = false

That overcomplicates it slightly though, the localscript is in the thing he wants to change around, he can just do script.Parent to get the StarterFrame, like how I did in my example

Yeah that works too, I skipped the thought of that.

1 Like

I tried it and it still didn’t work

Could it be that the game isn’t loaded by the time you’re entering? Maybe try this?

if not game:IsLoaded() then

local frame = script.Parent

frame.Visible = true
frame.Visible = false

oh, i got it do you know how to put the GUI in the player GUI.

Guis in StarterGui automatically replicate to each Player’s PlayerGui, so if you put it there, it’ll be placed there without having to do put it there yourself

ok I got it thank you :grinning: :grinning: :grinning: .

I know a solution has been made, but the Visible setting is unnecessary, just set the frame as visible by properties as default, then wait 5 seconds and set the visible property to false.