Pretty confusing error

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

1 Like

You know you can just put a script in starter character called Animate and it will use yours instead of the default roblox one right?

1 Like

But I still have another thing that will remove that one Animate script later
You know? The script can’t detect both at the same time.

So just delete that other script then and just do what I just said?

No it is very essential to my game’s mechanic

Youre confusing me quite a bit im not gonna lie.

1 Like

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

2 Likes

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
2 Likes

They could achieve the same goal with just placing it within StarterCharacterScripts.

The problem is I want only 1 Animate script exists inside the character at all time

Youre not supposed to have more than one XD

It would also be redundent to have more than one animate script.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.