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