Hi, does anyone know how I can make a local script to wait until a player loads before executing??? Sometimes the script bugs and it just doesn’t do anything and I have just a few lines to change some GUI text.
Where are you running the script and why does it need to wait for the player?
In the LocalScript
, you can wait for the player to fully load by using this:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
It will wait for their character to be added to the game, and then continue with the rest of the script.
It’s in the player gui and I need to wait so the GUIs load in before it tries to edit them
Are you referencing the guis directly or using gui:waitforchild()?
I’m referencing them directly
Trying using gui:waitforchild() instead and see if that helps.
Try adding this to the top of your localscript
repeat wait() until game:IsLoaded()
Did that work? If so you can mark my answer as the solution so it marks the forum as solved.
Personally i think doing this is a good idea, create a local script and put it in ReplicatedFrist. After put your Gui in the local script.
Put this in the local script
local ui = script:WaitForChild("TheGuiYourPutInTheLocalScript") -- This is the Gui Name in the script
repeat wait(1) until game:IsLoaded() -- Wait for game return true for IsLoaded
ui.Parent = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui") -- Put your GUI in the player GUI
I don’t test them so I don’t know if it works but I think it could work