Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local userInputService = game:GetService("UserInputService")
- local textButton = script.Parent
- local isSprinting = false
- local sprintSpeed = 50 -- The speed while sprinting
- local walkSpeed = 16 -- Default walking speed
- -- Function to toggle sprinting
- local function toggleSprint()
- if player.Character and player.Character:FindFirstChild("Humanoid") then
- local humanoid = player.Character.Humanoid
- if isSprinting then
- humanoid.WalkSpeed = walkSpeed
- isSprinting = false
- textButton.Text = "Sprint" -- Change button text when not sprinting
- else
- humanoid.WalkSpeed = sprintSpeed
- isSprinting = true
- textButton.Text = "Stop Sprinting" -- Change button text when sprinting
- end
- end
- end
- -- Connect button click (touch) to the sprint function
- textButton.MouseButton1Down:Connect(toggleSprint)
- -- Reset walk speed when player respawns
- player.CharacterAdded:Connect(function(newCharacter)
- newCharacter:WaitForChild("Humanoid").WalkSpeed = walkSpeed -- Reset speed when respawning
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement