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

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)
