Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I can't seem to figure out how to make a script that lets me toggle sprint?

I tried making a script where i can toggle on my sprint on and off but it didn't work, is there something that i'm missing?

local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftControl then
		humanoid.WalkSpeed = 35
	end
end)


UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftControl then
		humanoid.WalkSpeed = 16
	end
end)

1 answer

✓ Accepted answer

Your script will change the walkspeed while the key is pressed as you set it back on InputEnded.

You can add in a walk speed check to toggle sprint and remove the InputEnded event.

Example

local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftControl then
        if  humanoid.WalkSpeed == 35 then
			humanoid.WalkSpeed = 16
		else
			humanoid.WalkSpeed = 35
		end
    end
end)

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.