I tried making a toggle button for mobile users to sprint when you press it it does actually sprint but if you press it again nothing happens you stay sprinting I hope you understood
So how can I make it toggle?
Here is my code:
local ContextActionService = game:GetService("ContextActionService")
local char = game.Players.LocalPlayer.Character
local function Sprint()
char.Humanoid.WalkSpeed = 26
end
ContextActionService:BindAction("Sprint", Sprint, true, Enum.KeyCode.LeftShift)
local ContextActionService = game:GetService("ContextActionService")
local char = game.Players.LocalPlayer.Character
local toggle = 0
local function Sprint()
if toggle == 0 then
char.Humanoid.WalkSpeed = 26
toggle = 1
else
char.Humanoid.WalkSpeed = 16 -- default walk speed
toggle = 0
end
end
ContextActionService:BindAction("Sprint", Sprint, true, Enum.KeyCode.LeftShift)
local UserInputService = game:GetService("UserInputService")
local char = game.Players.LocalPlayer.Character
local toggle = 0
UserInputService.InputBegan:Connect(function(input, isTyping)
if not isTyping then
if input.KeyCode == Enum.KeyCode.LeftShift then
if toggle == 0 then
char.Humanoid.WalkSpeed = 26
toggle = 1
else
char.Humanoid.WalkSpeed = 16 -- default walk speed
toggle = 0
end
end
end
end)
You can do this to toggle key on PC. You may have to utilize some other code on mobile, however I am not particularly good at mobile development.