Ad
Log in to vote
0

Im trying to make a script that makes u faster when u press left shift but how?

Asked by
CMB1048 23
1 year ago
Edited 1 year ago

UserInputService = game:GetService("UserInputService") local players = game.Players.LocalPlayer

local LeftShiftPressed = false

UserInputService.InputBegan:Connect(function(input,gameProccesedEvent) if input.KeyCode == Enum.KeyCode.LeftShift then LeftShiftPressed = true if players:FindFirstChild("Humanoid") then players.Humanoid.CharacterWalkSpeed = 90

        UserInputService.InputBegan:Connect(function(input,gameProccesedEvent)
            if input.KeyCode == Enum.KeyCode.LeftShift then
                LeftShiftPressed = false
                if players:FindFirstChild("Humanoid") then
                    players.Humanoid.CharacterWalkSpeed = 16
    end
end

end)

        while LeftShiftPressed == true do
            wait()
            players.Humanoid.CharacterWalkSpeed = 90
        end
0
You have the code so what exactly do u need. Is your code not working? JustinWe12 719 — 1y
0
yes CMB1048 23 — 1y
0
it do not work CMB1048 23 — 1y
0
Can I see the variable for players? Xeqtricity 0 — 1y
View all comments (2 more)
0
/? CMB1048 23 — 1y
0
its at the beggining where it says game.Players.LocalPlayer CMB1048 23 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

So your not actually grabbing the player's character where the humanoid is. Instead of doing players:FindFirstChild("Humanoid"), create a variable for the character and replace players with it.

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

UserInputService.InputBegan:Connect(function(input,gameProcessed)
    --if not gameProcessed then
        if input.KeyCode == Enum.KeyCode.LeftShift then
                    if players:FindFirstChild("Humanoid") then
                        players.Humanoid.CharacterWalkSpeed = 90
            end
        end
    --end
end

Also, instead of using a loop to check if the player is sprinting, use the InputEnded function.

UserInputService.InputEnded:Connect(function(input,gameProcessed)
    --if not gameProcessed then
        if input.KeyCode == Enum.KeyCode.LeftShift then
                    if players:FindFirstChild("Humanoid") then
                        players.Humanoid.CharacterWalkSpeed = 16
            end
        end
    --end
end

if you want the player to sprint while using chat, keep the gameprocessed and the end that goes with it commented. If you do uncomment them, the player won't be able to sprint while using shift-lock.

Ad

Answer this question