Sprint Button not working at all

  1. What do you want to achieve? A simple sprint button for mobile players

  2. What is the issue? Players clicking on the button does nothing at least not even changing the text.

  3. What solutions have you tried so far? Tried debugging when the text change but it does not even print.

local function sprint() 
	if string.lower(toggletxt) == "Walk" then
		if Humanoid.MoveDirection.Magnitude > 0 then
			if not (character.Humanoid.WalkSpeed <= 7) then
				toggletxt = "sprint"
				sprinting = true
				while stamina > 0 and stamina do
					stamina = stamina - .03
					Bar.Size = UDim2.new(stamina / 10, 0, 1, 0)
					tween:Play()
					wait()
					if stamina <= 0 then
						tween2:Play()
						runninganim:Stop()
						sprinting = false
						character.Humanoid.WalkSpeed = NormalWalkSpeed
					end
				end
			end
		end
	elseif string.lower(toggletxt) == "Sprint" then
		if not (character.Humanoid.WalkSpeed <= 7) then
			toggletxt = "walk"
			character.Humanoid.WalkSpeed = NormalWalkSpeed
			sprinting = false
			runninganim:Stop()
			while stamina < 10 and not sprinting do
				stamina = stamina + .03
				Bar.Size = UDim2.new(stamina / 10, 0, 1, 0)
				tween2:Play()
				wait()
				if stamina <= 0 then
					tween2:Play()
					runninganim:Stop()
					character.Humanoid.WalkSpeed = NormalWalkSpeed
				end
			end
		end
	end
	if  character.Humanoid.WalkSpeed == 0 and runninganim.IsPlaying then
		runninganim:Stop()
	end
end
button.MouseButton1Down:Connect(sprint)

thanks in advance!

1 Like

Bump still looking for help! any better alternatives always welcome!

I tried Activated but it does not also work.

Please provide the full script.

That is the entire script. It is a localscript located in starterplayer.

You are lowering the text, So it cant be Walk

Correct way:
string.lower(toggletxt) == "walk"

same here

where’s the GUI button the button variable is assigned to?

the gui is found inside a screengui which is later parented to playergui for convenience of editing it locally.

MouseButton1Down will fire for mobile devices upon a tap of the touchscreen.

1 Like

Tried that and still it doesn’t work.

Don’t know if you still need help but where is “toggletxt” defined in the script?

Uh no, I scraped the whole thing and made a script using .MouseButtonDown1