Just a little confused on what i got wrong here, doesn’t really work ingame but says nothing’s wrong with it.
local walkSpeed = 16
local runSpeed = 24
local function onKeyPress(player, input, isProcessed)
if isProcessed then
return
end
if input.KeyCode == Enum.KeyCode.LeftShift then
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = input.UserInputState == Enum.UserInputState.Begin and runSpeed or walkSpeed
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.WalkSpeed = walkSpeed
character:GetPropertyChangedSignal("Parent"):Connect(function()
if character.Parent == nil then
humanoid.WalkSpeed = walkSpeed
end
end)
end)
end)
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)
game:GetService("UserInputService").InputEnded:Connect(onKeyPress)