How can I make a player sprint when they push forward on the walk button On Mobile?

How can I make a player sprint when they push forward on the walk button On Mobile?

2 Likes

try this:

wait(3)
local state = "Walking"
local MobileUser = false
local MobileButtons = game.ReplicatedStorage["MobileButtonsFrame"]

local UserInputService = game:GetService("UserInputService")

local GuiService = game:GetService("GuiService")

if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled   and not UserInputService.GamepadEnabled and not GuiService:IsTenFootInterface() then
local player = game.Players.LocalPlayer
local playergui = player.PlayerGui
local MobileButtons2 = MobileButtons:Clone()
MobileButtons2.Parent = player.PlayerGui["MainGui"]
local WalkButton = MobileButtons2["WalkButton"]
local MaxSpeed = 25
local MinSpeed = 12
local Character = player.Character or player.CharacterAdded:wait()
while true do
wait(.1)
if Character:FindFirstChild("Humanoid") then
break
else
print("no humanoid found!")
end
end
local Humanoid = Character:WaitForChild("Humanoid")
WalkButton.MouseButton1Down:Connect(function()
if state == "Walking" then
state = "Running"
Humanoid.WalkSpeed = MaxSpeed
elseif state == "Running" then
state = "Walking"
Humanoid.WalkSpeed = MinSpeed
 end
end)
end