replicatedStorage.RemoteEvents.Sprint.OnServerEvent:Connect(function(H,i)local X=H.Character.Humanoid if i=="\066\101\103\097\110"and(X:GetState()==Enum.HumanoidStateType.RunningNoPhysics and X.MoveDirection.Magnitude>0)then sprintingPlayers[H.Name]=X.WalkSpeed X.WalkSpeed=X.WalkSpeed*sprintModifier elseif i=="\069\110\100\101\100"and sprintingPlayers[H.Name]then X.WalkSpeed=sprintingPlayers[H.Name]sprintingPlayers[H.Name]=nil end end)runService.Heartbeat:Connect(function()for H,i in pairs(players:GetChildren())do local X=i.Stamina local u=i.Name if not sprintingPlayers[u]then if X.Value>maxStamina then X.Value=maxStamina elseif X.Value<maxStamina then X.Value=X.Value+staminaRegen end else if X.Value>=sprintStaminaCost then X.Value=X.Value-sprintStaminaCost else i.Character.Humanoid.WalkSpeed=sprintingPlayers[u]sprintingPlayers[u]=nil end end 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 > 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)

runService.Heartbeat:Connect(function()
	for index, player in pairs(players:GetChildren()) do
		local stamina = player.Stamina
		local name = player.Name

		if not sprintingPlayers[name] then
			if stamina.Value > maxStamina then
				stamina.Value = maxStamina
			elseif stamina.Value < maxStamina then
				stamina.Value = stamina.Value + staminaRegen
			end
		else
			if stamina.Value >= sprintStaminaCost then
				stamina.Value = stamina.Value - sprintStaminaCost
			else
				player.Character.Humanoid.WalkSpeed = sprintingPlayers[name]
				sprintingPlayers[name] = nil
			end
		end
	end
end)
