Animation script not working

I’ve been trying to make an animate script for an NPC that i made and rigged in Blender. The default animate script just animated the idle, so i wanted to try to make my own, much simpler, and also working, but i didn’t know which proprety to use for the humanoid, so i asked ChatGPT (yes) to make me a script, i didn’t expect it to work, well it didn’t. So, i wanna know how can i fix this. (Also, yes, i know that ChatGPT isn’t perfect and that it should mostly be used as a last resort or even not used at all)

The script
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")
local Idle = Character:WaitForChild("Idle")
local Walk = Character:WaitForChild("Walk")

function onHumanoidMove(movement)
	if movement.Velocity.Magnitude > 0.1 then
		-- Rig is moving, play the walking animation
		Humanoid.Animator:PlayAnimation(Walk)
	else
		-- Rig is not moving, play the idle animation
		Humanoid.Animator:PlayAnimation(Idle)
	end
end

Humanoid.Move:Connect(onHumanoidMove)

You need to use LoadAnimation to make AnimationTracks you can use on your humanoid.

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")
local Idle = Humanoid.Animator:LoadAnimation(Character:WaitForChild("Idle"))
local Walk = Humanoid.Animator:LoadAnimation(Character:WaitForChild("Walk"))
-- I suggest putting the animations in a folder in replicatedstorage

Walk.Priority = Enum.AnimationPriority.Movement
Idle.Priority = Enum.AnimationPriority.Idle
Idle:Play() -- Make sure this is looped

Humanoid.Running:Connect(function(movement)
	if movement.Magnitude > 0.1 then
		Walk:Play(0)
	else
		Walk:Stop(0.2)
	end
end)

image
It just gave me this error message

Remove the .Magnitude and try again, I guess it’s not a Vector3.

Thanks you so much for your help!

1 Like

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