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:

1 Like

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

2 Likes

You’d have to do this:

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

Players.PlayerAdded:Connect(function(Player)
    Player.PlayerGui.ScreenGui.StarterFrame.Frame.Visible = true

    wait(5)

    Player.PlayerGui.ScreenGui.StarterFrame.Frame.Visible = false
end)
1 Like

You can just have the code without PlayerAdded event.

1 Like

@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
wait(5)
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

3 Likes

So you want me to do it like this.
me

1 Like

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
wait(5)
Gui.ScreenGui.StarterFrame.Visible = false
1 Like

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

1 Like

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

2 Likes

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
	game.Loaded:Wait()
end

local frame = script.Parent

frame.Visible = true
wait(5)
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.