I'm using a script that makes use of BodyForce so the character can jump higher, by checking the masses of every part of the character and using the total weight of all the parts. However, sometimes the character loads too early and the script isn't able to detect every part of the character, resulting in a smaller BodyForce and thus a smaller jump. How can I wait until every part of the character's loaded before using the script?
You can really just use the CharacterAdded
event to make sure that the character is fully loaded just as NotsoPenguin has stated in the comments:
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(s) --do body force action here print("Character Loaded!") end) end)
Or even if you are using a local-script, you can do something as the following:
local plr = game.Players.LocalPlayer local chr = plr.Character or plr.CharacterAdded:wait() print("Character Loaded!") --do body force action here
Now, if you are waiting for hats to be loaded in or so, you can also add:
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(s) repeat until s.ChildAdded:wait() == "Hat" print("Character Loaded!") end) end)
http://wiki.roblox.com/index.php?title=API:Class/Player/CharacterAdded http://wiki.roblox.com/index.php?title=User:JulienDethurens/Essays/Wait_method