Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I wait for the character to load in my script?

Asked by
Narunzo 172
5 years ago

I have a custom character load script that changes the character's re-spawn time and a name tag script in ScriptServices so that they run as soon as the player joins but I can't get the name tag script to wait for the character to load. This is the script:

local NameTagGui=game:GetService("ServerStorage"):WaitForChild("NameTagGui")
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
wait()
if not game:GetService("Workspace"):FindFirstChild(player.Name.."") then
wait()
return
else
local humanoid=character:FindFirstChild("Humanoid")
local head=character:FindFirstChild("Head")
humanoid.DisplayDistanceType="None"
local Clone=NameTagGui:Clone()
Clone.Parent=head
Clone.NameTag.Text=(player.Name)
end
end)
end)

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Just do

game.Workspace:WaitForChild(player.Name)

It will wait until the character is in Workspace.

0
Thank you it worked. I didn't think it was that simple. I made it wait for the Workspace too by doing game:GetService("Workspace"). Narunzo 172 — 5y
0
Nvm it works fine in studio but doesn't always work in game. Narunzo 172 — 5y
0
I simply fit the script into my character load script so that it would insert the name tag when the character loads. But this would have worked for anything else so thanks. I'll mark your answer as the solution. Narunzo 172 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I would simply do that before the player variables

wait()

Answer this question