Hi there! I am having an issue right now with changing animations for my game.
My script is the one from the Developer Hub.
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
local animateScript = character:WaitForChild("Animate")
animateScript.run.RunAnim.AnimationId = "rbxassetid://616010382" -- Run
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://616013216" -- Walk
animateScript.jump.JumpAnim.AnimationId = "rbxassetid://616008936" -- Jump
animateScript.idle.Animation1.AnimationId = "rbxassetid://616006778" -- Idle (Variation 1)
animateScript.idle.Animation2.AnimationId = "rbxassetid://616008087" -- Idle (Variation 2)
animateScript.fall.FallAnim.AnimationId = "rbxassetid://616005863" -- Fall
animateScript.swim.Swim.AnimationId = "rbxassetid://616011509" -- Swim (Active)
animateScript.swimidle.SwimIdle.AnimationId = "rbxassetid://616012453" -- Swim (Idle)
animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://616003713" -- Climb
end
local function onPlayerAdded(player)
player.CharacterAppearanceLoaded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
I changed all the Ids to the Levitation animations. When I run it, the first one, (the RunAnim) works fine, but then I get this error
10:09:48.844 - WalkAnim is not a valid member of StringValue "MRKYLO20.Animate.walk"
10:09:48.844 - Stack Begin
10:09:48.845 - Script 'ServerScriptService.ChangeAnimationScript', Line 12 - function onCharacterAdded
10:09:48.845 - Stack End
This does not make sense because the RunAnim is pretty much the same thing as the WalkAnim.
Why am I getting this error?
Any help would be very much appreciated!
You should remove animateScript.run.RunAnim.AnimationId = "rbxassetid://616010382" -- Run and it’ll probably work since that probably creates the foot steps, idk
Does adding a wait() right after waiting for animate script fix anything?
I tested the script in studio and it worked fine for me so I’m wondering if it has something to do with how quickly everything loads and it just needs a tiny bit more time to load all the children of the animate script.
Here’s what the script would look like with the wait() I mentioned
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
local animateScript = character:WaitForChild("Animate")
wait()
animateScript.run.RunAnim.AnimationId = "rbxassetid://616010382" -- Run
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://616013216" -- Walk
animateScript.jump.JumpAnim.AnimationId = "rbxassetid://616008936" -- Jump
animateScript.idle.Animation1.AnimationId = "rbxassetid://616006778" -- Idle (Variation 1)
animateScript.idle.Animation2.AnimationId = "rbxassetid://616008087" -- Idle (Variation 2)
animateScript.fall.FallAnim.AnimationId = "rbxassetid://616005863" -- Fall
animateScript.swim.Swim.AnimationId = "rbxassetid://616011509" -- Swim (Active)
animateScript.swimidle.SwimIdle.AnimationId = "rbxassetid://616012453" -- Swim (Idle)
animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://616003713" -- Climb
end
local function onPlayerAdded(player)
player.CharacterAppearanceLoaded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
hmm… I tried both solutions and neither of them worked, I am just stumped on why it is only the walk one, because I took the walk away to test, and all the others work…