You don’t need the repeat that’s unnecessary. That event will fire once the character has been added meaning the argument will already be the character immediately.
I want to set the character’s parents to workspace.Characters. But it can’t be done without using the script above. I want to know if anyone has a better way to wait for a character to fully load.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
while wait() do
if char:FindFirstChild("Humanoid") then
char.Parent = workspace.Characters
break
end
end
end)
end)
Look out for practices that could yield smelly code!
local function onPlayerAdded(player)
-- whatever things you'd like
player.CharacterAdded:Connect(function(character)
while not character:FindFirstChild("Humanoid") do
task.wait()
end
character.Parent = workspace.Characters
end)
end
for _, player in pairs(Players:GetPlayers()) do
-- pesky loading time if the player somehow loaded faster than the server
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
If the CharacterAdded is on the server, theres no need for you to wait. The CharacterAdded event waits for all character parts are loaded on the server.
Setting the characters parent when the character has just loaded is totally glitchy by the way, its necessary with a wait, from my testing the wait doesnt have to be big - I just did task.wait()