Hi I've made a emote gui which it's very working but after I reset my character the emotes doesn't work anymore and it pops up this error and I haven't figure out how to fix it yet : " Loadanimation requires the humanoid object (player1.Humanoid) to be a descendant of the game object "
Here's my script
01 | wait( 1 ) |
02 | local user = game.Players.LocalPlayer |
03 | repeat |
04 | wait() |
05 | until user.Character |
06 | local Input = game:GetService( "UserInputService" ) |
07 | local animen = script.Parent.Parent.Parent:WaitForChild( "Dances" ) |
08 | local speeder, speedval = animen:WaitForChild( "Speeddancehaha" ), 1 |
09 | local mouse = user:GetMouse() |
10 | local scrollingframe = script.Parent |
11 | local anim |
12 | local char = user.Character |
13 | local humanoid = char:WaitForChild( "Humanoid" ) |
14 | local ftime = 0.7 |
15 | function playanim(id, lola) |
Please help me fix this annoying errors
It's because you're not re-referencing the character's humanoid. Every time a character dies it destroys that old character and creates a new one, therefore, any references to character or humanoid are nil. You can fix the character like this
1 | local char = player.Character or player.CharacterAdded:Wait() -- This essentially runs and sais if the character then char == character if not then it waits till its added and then it's then the character |
The humanoid you could just re-reference every time you call the playanim function like so
1 | function playAnim() |
2 | local humanoid = char.Humanoid or char:WaitForChild( "Humanoid" ) -- This either gets the valid humanoid or waits for a valid humanoid |
3 | end |
If this answers your question please mark it as answered or an upvote. Good luck!
Try doing LocalScript and doing FireServer, but don't put LocalScript in the gui that doesn't restart when restarting