For the start of my LocalScript, I put a repeating until all the stats in the player is loaded then I put a wait(.1)
repeat wait(.2) until game.Players.LocalPlayer.StatsLoaded and game.Players.LocalPlayer.StatsLoaded==true wait(.1) sp=script.Parent local Plr=game.Players.LocalPlayer local plrgui=Plr:findFirstChild("PlayerGui") local StarterGui=game:GetService("StarterGui") local Mouse=Plr:GetMouse() local Char=Plr.Character if not Char or Char.Parent==nil then Char=Plr.CharacterAdded:wait() end Hum=Char:WaitForChild("Humanoid") local CP=game:GetService("ContentProvider") local Str=sp:WaitForChild("Start") local Gm=sp:WaitForChild("Game")
I know the script should error if it can't detect or find the defined values but it doesn't look like it would have any trouble finding it. I'd put a longer wait at the beginning but I don't want everyone to have a 2 second delay after every time they die (This is for a fort). So is there a better way to find some of these things, especially the Player's Character and Humanoid?
As far as I know, you should only ever have to wait momentarily (e.g., your wait(0.2)
) to get the objects in the StarterGui (or wherever else you put it) to load with the script, so getting Str
and Gm
at least could probably be doing using just sp.Start
rather than using WaitForChild.
I'm not sure what you mean by the StatsLoaded
. If it's just a child, you can use :WaitForChild("StatsLoaded")
. In any case, it will never be equal to true, so your repeat until
shouldn't ever stop.