I am using a script that inserts a custom animation script into a character. The script is located in ServerScriptStorage.
The issue is this script only sometimes works. I placed print commands in the text and sometimes when ran, the only output is 0 and not 1 or 2, meaning that the script is not detecting the character.
Here is the script:
When handling a player added or removed event, with the expectations of it running as soon as possible. Make sure to place it in a script that has no delays before hooking up the event listener.
For example, if you’re waiting on a specific part to appear in game, and then hook the event listener. The player may have already joined, thus missing the purpose of the function.
Here’s a short example in code:
game.Workspace:WaitForChild("Part")
game.Players.PlayerAdded:Connect(function(player)
-- Some code.
end
The player may have joined before the game.Players:Connect(function(player) event listener was hooked up because we were waiting on a part.
Instead, you’d do the following to guarantee that the function is already hooked up.
game.Players.PlayerAdded:Connect(function(player)
-- Some code.
end)
game.Workspace:WaitForChild("Part")
Also what you are doing is swapping out anims, Instead merely put the script in local character scripts and it will replace the animate for you aslong as both local scripts are the same name
on another note, I didn’t get any errors from your code when i add in the anim script parented under script.
Well the thing is I have two different custom characters and I am trying to give them two separate animations, it works so far its just sometimes it doesn’t go past print(0).
I don’t believe it would because the custom characters are only morphed a gui button is pressed, and when testing the game, the original animation script is not being deleted even before pressing the morph button.
Oh my gosh I forgot I had that on, nor did I realize it would effect it but yes I did, I just turned it off and so far its working properly now, thanks for everyone that was helping me out!