Help with shift to run

I want to add shift to run to my game and so far ive tested lot of scripts and they dont seem to function as i want them to , i wanna make the walk speed of the character a little slow to provide realism but whenever i set the walk speed to 10 and run speed 16 it dosent work as intented the character starts with the default walk speed of 16 on spawn and it changes only when the shift key is pressed , it also bugs out in my character customization and cutscenes the players can freely roam there even tho its set that the speed is 0 while the gui is open.

Any help is appreciated
Thanks

3 Likes
local userInputService = game:GetService("UserInputService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local SPRINT_SPEED = 16
local WALK_SPEED= 10

local function updateSpeed(speed)
  humanoid.WalkSpeed = speed
end

userInputService.InputBegan:Connect(function(input,gp)
  if gp then return end
  if input.KeyCode == Enum.KeyCode.LeftShift then
    updateSpeed(SPRINT_SPEED)
  end
end)

userInputService.InputEnded:Connect(function(input,gp)
  if gp then return end
  if input.KeyCode == Enum.KeyCode.LeftShift then
    updateSpeed(WALK_SPEED)
  end
end)

updateSpeed(WALK_SPEED)

this should work

2 Likes

Thanks i tested it and it works
Thankss so much this will be really helpful for my game

2 Likes