Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Sorukan 240 Moderation Voter
5 years ago
Edited 5 years ago
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

Log in to vote
0
Answered by 5 years ago

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)

1
they both say InputBegan the8bitdude11 358 — 5y
0
Thanks it works now! Sorukan 240 — 5y
0
My bad. On line 13 you should change InputBegan to InputEnded ScrubSadmir 200 — 5y
Ad
Log in to vote
1
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
5 years ago

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

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? Sorukan 240 — 5y
0
I assumed it was a free model because you had no idea how to change Control to Shift RubenKan 3615 — 5y

Answer this question