so im trying to make it so that when I press 'x' it'll change the walk speed as well as play a run animation i made, but i get an error saying 'Unable to cast value to Object' and it's pointing at line 15
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local sprinting = false local sprint = script.SprintAnim if not character or not character.Parent then character = player.CharacterAdded:wait() end wait() local hum = character:WaitForChild("Humanoid") mouse.KeyDown:connect(function(key) local sprintPlay = hum:LoadAnimation("SprintAnim") if key == "x" then if sprinting then sprinting = false sprintPlay:Stop() else sprinting = true sprintPlay:Play() end game.ReplicatedStorage.SprintToggle:FireServer(sprinting) end end)
ps: this is a local script
You should be passing an Animation to Humanoid:LoadAnimation()
, not a string.
Also Humanoid:LoadAnimation()
is deprecated and you should use Animator:LoadAnimation().