I wanted to create sprint activation/deactivation at the click of a button. The problem is that in the function, the second condition does not work.
local UserInputService = game:GetService("UserInputService")
local sprintButton = script.Parent.sprint
local sprintActive = script.Parent.sprint_active
local jumpButton = script.Parent.jump
local keyPressed = false
local humanoid = nil
if UserInputService.TouchEnabled then
script.Parent.Enabled = true
else
script.Parent.Enabled = false
end
sprintButton.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.Character then
humanoid = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid")
end
if humanoid and not keyPressed then
print("on")
keyPressed = true
humanoid.WalkSpeed = 33.98
sprintActive.Visible = true
elseif humanoid and keyPressed then
print("off")
keyPressed = false
humanoid.WalkSpeed = 17.5
sprintActive.Visible = false
end
end)