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

LocalScript in StarterCharacterScript is not working?

Asked by
Neon_N 104
5 years ago
Edited 5 years ago
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = Char:WaitForChild("Humanoid")

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
    local keyPressed = input.KeyCode
        if keyPressed == Enum.KeyCode.LeftShift then -- put key in parenthesis
                Char.Humanoid.WalkSpeed = 32
        end
end)

UserInputService.InputEnded:Connect(function(input)
    local keyReleased = input.KeyCode
        if keyReleased == Enum.KeyCode.LeftShift then -- put key in parenthesis
                Char.Humanoid.WalkSpeed = 16
        end
end)

Why is this not working?

0
functions not closed? no? TheluaBanana 946 — 5y
0
What function Neon_N 104 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

You are directing the KeyCode without the Enum being used. Fixed script:

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
humanoid = Char:WaitForChild("Humanoid") -- humanoid should be global not local

UserInputService = game:GetService("UserInputService") -- also should be global

UserInputService.InputBegan:Connect(function()
        if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then -- use IsKeyDown()
                humanoid.WalkSpeed = 32
        end
end)

UserInputService.InputEnded:Connect(function()
                humanoid.WalkSpeed = 16
end)
Ad

Answer this question