Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

'Unable to cast value to object' error... can anyone help?

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

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.