I keep running into problems with the CharacterAdded event. It is used to find the new character after death but it is being executed too early causing some limbs to not be loaded tough causing an error.
I already tried adding wait() and using WaitForChild() ( “lag” ) whitout sucess.
Would there be a way to fix this or another way of finding the new character?
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(character)
-- character is your loaded character
end)
end)
That’s strange because i have this function in my game and it adds a hitbox to character.
Alright i have just checked it and it works every time the character is added to the workspace. (not only when he enters the game)
I’m trying to do a custom camera system which imply finding the head. This is the limb that I’m trying to get after the player dies so the script could work properly.
I don’t understand how I would go about using this. The function yields until all the given instances are loaded but in my case it is impossible to reference the head until it is loaded. This makes the method useless as the head would not be in the table making the function ignore it.
I have two possible solutions. One is to use task.wait() before trying to index the head. task.wait() makes sure a physics step runs before the thread continues. This step is where the limbs are added.
My second solution would to be add a local head = character:WaitForChild("Head)
and index the head with that variable.
Examples:
Solution 1:
local player = game.Players.LocalPlayer
player.CharacterAdded:Connect(function(character)
task.wait()
print(character.Head.Name)
end)
Solution 2:
local player = game.Players.LocalPlayer
player.CharacterAdded:Connect(function(character)
local head = character:WaitForChild("Head")
print(head.Name)
end)
Hope this helps! Let me know if I understood the question wrong or you have any questions.
My problem is that when the event fires, a lot of the times the head is not loaded in the character model making it impossible to reference it as it is not “there” ( loaded ). The reason I said
is because we want to use PreloadAsync() to check when it is loaded but it needs to know what to check which is already what we are trying to solve; we can’t use this as the head don’t “exist” until it is loaded.