Remote event giving an exhausted error unable to fix

The timer that is used in the local script that follow starts off at two minutes. The timer should go up by 20 seconds after the player buys the “speed coil” item. However, when I run these scripts, I get a “exhaust error”.

It’s because of my newElapsed time is running continuously but I don’t know how else I can update the text without getting the exhaust error.

https://gyazo.com/09d3efc307063f1e45613abcd6099b6f

Local script under the textlabel:

local RunService = game:GetService("RunService")
local textLabel = script.Parent
local oldElapsed = 0
local remoteEvent = game:GetService("ReplicatedStorage").RemoteEvent


local function formatTime(currentTime)
	local hours = math.floor(currentTime/3600)
	local minutes = math.floor((currentTime - (hours * 3600))/60)
	local seconds = math.floor((currentTime - (hours * 3600) - (minutes * 60)))
	local milliseconds = 1000 * (currentTime - math.floor(currentTime))
	local format = "%02d:%02d:%02d:%03d"
	return format:format(hours, minutes, seconds, milliseconds)
end
	

local function startTimer(currentTime)
	RunService.Stepped:Connect(function(newElapsed, step)
		oldElapsed = math.floor(oldElapsed)
		currentTime -= step
		if currentTime <= 0 then
			textLabel.Text = "Completed timer!"
			return
		end
		textLabel.Text = formatTime(currentTime)
		remoteEvent:FireServer(newElapsed)
	end)
end


startTimer(40)

Script under serverscriptservice:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local speedCoil = game:GetService("ServerStorage").SpeedCoil
local Players = game:GetService("Players")
local remoteEvent = ReplicatedStorage.RemoteEvent
local textLabel = game:GetService("StarterGui").ScreenGui.TextLabel



local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")

local productFunctions = {}

productFunctions[1780413266] = function(receipt, player)
	local backPack = player:FindFirstChildOfClass("Backpack")
	if backPack then
		local clonedSpeedCoil = speedCoil:Clone()
		local playerHasTool = player.Character:FindFirstChild("SpeedCoil") or player.Backpack:FindFirstChild("SpeedCoil")
		if playerHasTool then
			clonedSpeedCoil:Destroy()
			remoteEvent.OnServerEvent:Connect(function(player, newElapsed)
				newElapsed += 20
			end)
		else
			clonedSpeedCoil.Parent = backPack
		end
		return true
	end
end

Yeah, this event fires roughly every 10-20 milliseconds. Each time it does, you’re firing the RemoteEvent - This is way faster than a RemoteEvent can handle. You’re gonna need to lower the firing rate.

1 Like

I’m not seeing where the product function is being called.

Otherwise there is no OnServerEvent connection.

It’s being called when a part is touched, there’s a seperate script for that that prompts the product when the part is touched