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?
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)