"LoadAnimation is not a valid member of Model Workspace.KayneWestReal"

I’m working on a script that will let the character dash a direction when they press E.

When I press E to dash I get the error in the title “LoadAnimation is not a valid member of Model Workspace.KayneWestReal” and am directed to the line that goes
“local playanim = player.Character:LoadAnimation(anim)”
I assumed it was a simple issue originally but I have been working on this for a few hours now with no success, anyone have any ideas?

My code:

dashremote.OnServerEvent:Connect(function(player, dir)

if not candash then return end
candash = false

local char = player.Character 
local Humanoid = char:WaitForChild("Humanoid")
local root = char:FindFirstChild("HumanoidRootPart")

local bv = Instance.new("BodyVelocity", root)
bv.MaxForce = Vector3.new(1,1,1) * 30000
bv.Velocity = root.CFrame * CFrame.Angles(0,math.rad(dir), 0).lookVector * 120

game.Debris:AddItem(bv, dashDuration)
local anim = script.DashForward
if dir == 180 then
	anim = script.DashBackward
elseif dir == 90 then 
	anim = script.DashLeft
elseif dir == -90 then
	anim = script.DashRight

local playanim = player.Character:LoadAnimation(anim)


wait(dashCooldown - dashDuration)
candash	= true



local playanim = player.Character.Humanoid:LoadAnimation(anim)


You must load an animation on to the animator like so:

local playanim = player.Character.Humanoid.Animator:LoadAnimation(anim)

Thanks dude this worked immediately lol

1 Like

@KayneWestReal actually, @trackysecretagent is correct, you shouldn’t load animations to Humanoids and/or AnimationControllers as of a couple of weeks ago, when first announcement came out, discouraging developers from doing that. There were a couple of errors discovered, as animations are actually loaded to animators, which are descendats of those two objects.

local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

local anim = animator:LoadAnimation(anim)

Only load animation once, and play or stop it. No need to ever load it to the same character multiple times.

1 Like