I have a problem that if you hold LeftShift down to Sprint and let go of "W" you'll stop sprinting but your Stamina/Energy will still drain... I believe it's in this part of the code
-- Sprint key pressed or released replicatedStorage.RemoteEvents.Sprint.OnServerEvent:Connect(function(player, state) local humanoid = player.Character.Humanoid if state == "Began" and humanoid:GetState() == Enum.HumanoidStateType.RunningNoPhysics and humanoid.MoveDirection.Magnitude > 0 then sprintingPlayers[player.Name] = humanoid.WalkSpeed humanoid.WalkSpeed = humanoid.WalkSpeed * sprintModifier elseif state == "Ended" and sprintingPlayers[player.Name] then humanoid.WalkSpeed = sprintingPlayers[player.Name] sprintingPlayers[player.Name] = nil end end)
but I am not sure how to go about it. Basically I want you to be able to hold LeftShift down as much as you'd like but only use your Stamina/Energy if you're actually moving. If you need to see more code just ask. Thanks in advance for any help/feedback!
[EDIT] After messing around I think maybe it's in this section of code?
-- Sprint Key Pressed userInputService.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then replicatedStorage.RemoteEvents.Sprint:FireServer("Began") end end) -- Sprint Key Released userInputService.InputEnded:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then replicatedStorage.RemoteEvents.Sprint:FireServer("Ended") end end)
-- Sprint key pressed or released replicatedStorage.RemoteEvents.Sprint.OnServerEvent:Connect(function(player, state) local humanoid = player.Character.Humanoid if state == "Began" and humanoid:GetState() == Enum.HumanoidStateType.RunningNoPhysics and humanoid.MoveDirection.Magnitude > 1 then sprintingPlayers[player.Name] = humanoid.WalkSpeed humanoid.WalkSpeed = humanoid.WalkSpeed * sprintModifier elseif state == "Ended" and sprintingPlayers[player.Name] then humanoid.WalkSpeed = sprintingPlayers[player.Name] sprintingPlayers[player.Name] = nil end end)
then change that if you walk Enum.HumanoidStateType.RunningNoPhysics and humanoid.MoveDirection.Magnitude it is smaller than 1.
I think this may help I do not know.