How can I fix my mobile sprint button

local contextActionService = game:GetService("ContextActionService")

local function mobileSprint()
	if sprinting == false then
		char.Humanoid.WalkSpeed = sprint
		contextActionService:SetTitle("Sprint", "Walk")
		sprinting = true
		wait(1)
	elseif sprinting == true then
		char.Humanoid.WalkSpeed = default
		contextActionService:SetTitle("Sprint", "Sprint")
		sprinting = false
		wait(1)
	end
end

local button = contextActionService:BindAction("Sprint", mobileSprint, true, "control")
contextActionService:SetTitle("Sprint", "Sprint")

My code here is for my mobile sprint. But when testing in studio, I press the button (just once) and it goes from sprinting to not right away.

How do I fix it?