Lowkey got no clue why it doesn’t work, I’ve provided booleans so it doesn’t get stuck, I even used run service
local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
local Sprintevent = rs:WaitForChild("Sprint")
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local isSprinting = false
uis.InputBegan:Connect(function(input,e)
if e then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
if isSprinting == true then
hum.WalkSpeed = 16
isSprinting = false
end
if isSprinting == false then
hum.WalkSpeed = 32
isSprinting = true
end
end
end)```
Your main issue is the line if e then return end. It could be that you have ShiftLock enabled, which counts as a gameProcessEvent.
Here’s a cleaned up version, although I removed the event part:
local userInputService = game:GetService('UserInputService')
local replicatedStorage = game:GetService('ReplicatedStorage')
local localPlayer = game:GetService('Players').LocalPlayer
localPlayer.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild('Humanoid')
local isSprinting = false
local inputEvent = userInputService.InputBegan:Connect(function(input,e)
isSprinting = not isSprinting
if input.KeyCode == Enum.KeyCode.LeftShift then
if isSprinting then
humanoid.WalkSpeed = 32
else
humanoid.WalkSpeed = 16
end
end
end)
local characterRemoving
characterRemoving = character:GetPropertyChangedSignal('Parent'):Connect(function()
if not character.Parent then
inputEvent:Disconnect()
characterRemoving:Disconnect()
character,humanoid,isSprinting,inputEvent,characterRemoving = nil
end
end)
end)
There are two issues with the script. The first being it doesn’t activated and of the statements below
“if e then return end”
The second argument in InputBegan is “GameProcessedEvent” these happen when you don’t want to activate inputs whilst you’re typing or in a menu etc… This needs to be
if not e then return end
not the other way.
You also don’t have any returns in your if statements. you need to add “return”
FINAL CODE:
local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
local Sprintevent = rs:WaitForChild("Sprint")
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local isSprinting = false
uis.InputBegan:Connect(function(input,e)
if not e then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
if isSprinting == true then
hum.WalkSpeed = 16
isSprinting = false
return
end
if isSprinting == false then
hum.WalkSpeed = 32
isSprinting = true
end
end
end)