So I’m trying to replace the player’s default animation with mine so I tried to delete the original and add mine
Here’s the code:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait() -- Wait for the character to spawn
local Humanoid = Character:WaitForChild("Humanoid")
Character:WaitForChild("Animate"):Destroy() -- Destroy the default animations
local Tracks = Humanoid:GetPlayingAnimationTracks() -- Get all playing animations from our character
for i, thistrack in pairs(Tracks) do -- Stop and destroy all animations that are playing
thistrack:Stop()
thistrack:Destroy()
end
local NewAnimScript = game:GetService("Workspace"):FindFirstChild("Animate")
NewAnimScript.Parent = Character
NewAnimScript.Disabled = false
When I first entered the server, the script works just fine
But when I reset my character, the script broke, leading to my player just doing the standing animation
The error also said:
Workspace.err_nothing.defaultanim:15: attempt to index nil with ‘Parent’ - Client - defaultanim:15
Tô replace the animation every time the player respawn you need make a Script that wait the CharacterAdded and find the local script from default animation for remove and put the custom animation
The reason is that after putting the “Animate” script once, the workspace no longer contains it. Use :Clone()
Try this:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait() -- Wait for the character to spawn
local Humanoid = Character:WaitForChild("Humanoid")
Character:WaitForChild("Animate"):Destroy() -- Destroy the default animations
local Tracks = Humanoid:GetPlayingAnimationTracks() -- Get all playing animations from our character
for i, thistrack in pairs(Tracks) do -- Stop and destroy all animations that are playing
thistrack:Stop()
thistrack:Destroy()
end
local NewAnimScript = game:GetService("Workspace"):FindFirstChild("Animate"):Clone()
NewAnimScript.Parent = Character
NewAnimScript.Disabled = false