Roblox Mobile joystick walkspeed issue

Hey everyone, I’m facing a small script issue where:

  • This is a script which build’s the players speed overtime while they are running.
  • For now there’s a bug which for some reason (I think has to do with mobile joystick) causing mobile player’s humanoid to not increase in speed
  • Works fine for pc just mobile.
  • Animation tracks and everything work for mobile, just the walkspeed isnt updating.
  • Extra Information: The Attribute “SpeedOn” is an attribute made by a text button upon mouseclick1 which just creates the attribute in the character, this creates a connection between both local scripts.
  • I do believe the issue is with the joystick/ mobile player controller

EDIT 2: Walkspeed isnt updated/changed on mobile while pc walkspeed updates

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local walkAnimId = "rbxassetid://913376220"
local runAnimId = "rbxassetid://137751793272237"
local idleAnimation = "rbxassetid://0"

local PlrStats = player:WaitForChild("PlrStats").Normal

if PlrStats.Value == "RF" then
	idleAnimation = "rbxassetid://78170311052745"
end

if PlrStats.Value == "Base" then
	idleAnimation = "rbxassetid://110113574035386"
end

local animPlaying = false
local walkAnimPlaying = false
local idlePlaying = false
local trackspeed = 1

local runSpeedMax = 0

local speedEnabled = false
local owns2xGP = false

local walkAnim = Instance.new("Animation")
walkAnim.AnimationId = walkAnimId
walkAnim.Name = "WalkAnimation"

local runAnim = Instance.new("Animation")
runAnim.AnimationId = runAnimId
runAnim.Name = "RunAnimation"

local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator")
animator.Parent = humanoid

local animation = Instance.new("Animation")
animation.AnimationId = runAnimId
local track = animator:LoadAnimation(animation)

local animationwalk = Instance.new("Animation")
animationwalk.AnimationId = walkAnimId
local trackwalk = animator:LoadAnimation(animationwalk)

local animationIdle = Instance.new("Animation")
animationIdle.AnimationId = idleAnimation
local trackIdle = animator:LoadAnimation(animationIdle)

function increaseSpeedGradually()

	if owns2xGP == true then
		humanoid.WalkSpeed = humanoid.WalkSpeed + 0.2

		local newsum = humanoid.WalkSpeed + 0.2
		runSpeedMax = newsum
		humanoid.WalkSpeed = newsum
		
		print("RunSpeed: "..runSpeedMax.. "WalkSpeed: "..humanoid.WalkSpeed)
	end

	if owns2xGP == false then
		humanoid.WalkSpeed = humanoid.WalkSpeed + 0.1

		local newsum = humanoid.WalkSpeed + 0.1
		runSpeedMax = newsum
		humanoid.WalkSpeed = newsum
		
		print(runSpeedMax)
	end
end

function checkforGP()

	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local MarketplaceService = game:GetService("MarketplaceService")

	local CheckGamepassRF = game.ReplicatedStorage.Check2xSpeedGamepass

	local SPEED_GAMEPASS_ID = 1329636681

	local hasGamepass = CheckGamepassRF:InvokeServer()
	if hasGamepass == true then
		owns2xGP = true
	end
end
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then

		if speedEnabled == true then
			speedEnabled = false
			return
		end

		if speedEnabled == false then
			speedEnabled = true
			return
		end

	end

end)

checkforGP()

while wait() do

	if speedEnabled == true or player.Character:GetAttribute("SpeedOn") == true then
		if humanoid.MoveDirection.Magnitude > 0 then
			
			print("Player movement was greater than 0")

			humanoid.WalkSpeed = runSpeedMax
			
			print(runSpeedMax)

			if not animPlaying then
				track:Play()
				animPlaying = true
			end

			if humanoid.WalkSpeed < 1500 then
				increaseSpeedGradually()
				print("Player speed increased")
			end

			trackspeed = humanoid.WalkSpeed / 10
			track:AdjustSpeed(trackspeed)

			if idlePlaying then
				trackIdle:Stop()
				idlePlaying = false
			end

			if trackIdle.IsPlaying then
				trackIdle:Stop()
			end
		end

		if humanoid.MoveDirection.Magnitude <= 0 then
			if not idlePlaying then
				for _, track in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
					track:Stop()
				end

				trackIdle:Play()
				idlePlaying = true
				animPlaying = false
			end
		end
	end

	if speedEnabled == false then
		if humanoid.MoveDirection.Magnitude > 0 then

			humanoid.WalkSpeed = 16

			if walkAnimPlaying == false then
				trackwalk:Play()
				walkAnimPlaying = true
				idlePlaying = false
			end

			if idlePlaying then
				trackwalk:Stop()
				idlePlaying = false
			end

			if trackIdle.IsPlaying then
				trackIdle:Stop()
			end
		end

		if humanoid.MoveDirection.Magnitude <= 0 then
			if not idlePlaying then
				for _, track in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
					track:Stop()
				end

				trackIdle:Play()
				idlePlaying = true
				walkAnimPlaying = false
			end
		end
	end
	
	if player.Character:GetAttribute("SpeedOn") == false then
		if humanoid.MoveDirection.Magnitude > 0 then

			humanoid.WalkSpeed = 16

			if walkAnimPlaying == false then
				trackwalk:Play()
				walkAnimPlaying = true
				idlePlaying = false
			end

			if idlePlaying then
				trackwalk:Stop()
				idlePlaying = false
			end

			if trackIdle.IsPlaying then
				trackIdle:Stop()
			end
		end

		if humanoid.MoveDirection.Magnitude <= 0 then
			if not idlePlaying then
				for _, track in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
					track:Stop()
				end

				trackIdle:Play()
				idlePlaying = true
				walkAnimPlaying = false
			end
		end
	end


end

Note: Everything works properly on PC just mobile’s joysticks seem to not work with the script

It looks like to me you are using UserInputService to detect when E is pressed to enable the speedup. A mobile player does not have a keyboard, therefore they cannot activate it by pressing E. UserInputService is generally superseded by ContextActionService which avoids issues like this.

There’s a text button GUI which acts as a substitute for the variable, clicking the button toggles a attribute called “SpeedOn” in the character which is used in a or condition with the variable, its a bit lower in the while wait() do loop. I think it was like

if speedEnabled == true or player.Character:GetAttribute("SpeedOn") == true then

SpeedOn is created only by the mobile button only accessible by mobile players thus there isnt really any conflict between the attribute and the variable speedEnabled.

Thanks for responding though, still having troubles with this. I still think the cause is the joystick for mobile.


Also, the track animation speed etc all work its just not the walkspeed being update for mobile players, it works for pc but not mobile. Debug prints everything and it says its being updated but looking in properties it stays at 16 as the walkspeed (only for mobile, pc walkspeed increases)