Question about sprint toggles

weird, looks fine to me, except for :play() being lowercase, i think you shouldnt do .Changed and instead do everything in .InputBegan like i showed you in one of my previous messages. If this doesn’t help then it’s something with your animation

local UserInputService = game:GetService("UserInputService")

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid") :: Humanoid
local Animator = Humanoid:WaitForChild("Animator") :: Animator

local Animation = script.Animation
local SprintAnimation = Animator:LoadAnimation(Animation)
local IsSprinting = false

local function ChangeSprintState(NewState: boolean?)
	local ShouldSprint = NewState == true or (not IsSprinting and Humanoid.MoveDirection.Magnitude > 0)
	
	if ShouldSprint then
		Humanoid.WalkSpeed = 24
		SprintAnimation:Play()
	else
		Humanoid.WalkSpeed = 16
		SprintAnimation:Stop()
	end
	
	IsSprinting = ShouldSprint
end

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if Humanoid.MoveDirection.Magnitude == 0 then
		if IsSprinting then
			ChangeSprintState(false)
		end
	end
end)

UserInputService.InputBegan:Connect(function(Input: InputObject, GameProcessedEvent: boolean)
	if GameProcessedEvent then return end
	if Input.KeyCode == Enum.KeyCode.Q then
		ChangeSprintState()
	end
end)

The script I sent fixes the problem and it handles it better.

il check if this works for what im going for

it does not stay in the sprinting state,

it immediatly goes back to walking, i think because of the

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if Humanoid.MoveDirection.Magnitude == 0 then
		if IsSprinting then
			ChangeSprintState(false)
		end
	end
end)

that it goes back to walking immediatly after the character stops moving, but thats not what im going for


just to make it more clear ^^)