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

How can i change sprinting script to make it so that it only works when i hold down left control?

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)

I placed this script in the StarterCharacterScripts and i'm not sure how to make it so that it only changes my walkspeed if i hold shift.

2 answers

✓ Accepted answer

If you made this script, then just use UserInputService's InputEnded event. This event fires whenever the input service is not active anymore, in your case, when the left control key is not held down anymore. I also the gameProcessed parameter so your player's walk speed doesn't change when the player is typing.

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

local UIS = game:GetService("UserInputService")

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

UIS.InputBegan:Connect(function(input,gameProcessed)
    if gameProcessed then return end
    if input.KeyCode == Enum.KeyCode.LeftControl then
        humanoid.WalkSpeed = 16
    end
end)

3 comments

1

they both say InputBegan

0

Thanks it works now!

0

My bad. On line 13 you should change InputBegan to InputEnded

We don't really help with free models, but you can change LeftControl to LeftShift on line 7.

2 comments

0

I made this script and i meant left control not shift, that was my bad but how could you just assume that it was a free model?

0

I assumed it was a free model because you had no idea how to change Control to Shift

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