I’m trying to make a saving system but it just keeps saying this when I spam the remote event,
I expected it to not happen since I’m waiting 2 (or more) seconds until I can save again.
This is my code (not the entire thing) ;
for i = 1, 25 do
if cooldown then
repeat task.wait(.5) until not cooldown
else
break
end
task.wait(.5)
end
cooldown = true
Store:SetAsync(Plr.UserId,EncodedData)
print('[SERVER] Saved loadout for ' .. Plr.Name .. '!')
task.wait(2)
cooldown = false
Anyone know how to make it stop warning this? Thanks in advance.
Full Code
local Storage = game:GetService('ReplicatedStorage')
local DS = game:GetService('DataStoreService')
local HS = game:GetService('HttpService')
local Store = DS:GetDataStore('Towers')
local Module = require(Storage.MainModule)
local cooldown = false
Storage.SaveData.OnServerEvent:Connect(function(Plr,Data:{ Loadout:{number},Towers:{number} })
if Data['Loadout'] == nil or Data['Towers'] == nil then
Plr:Kick('Data given by client does not have "Loadout" or "Towers".')
return
end
for _, ID in Data.Loadout do
if not table.find(Data.Towers,ID) and ID ~= 0 then
Plr:Kick('Data given by client has specific IDs in "Loadout" but not in "Towers"')
return
end
end
local EncodedData = HS:JSONEncode(Data)
if EncodedData then
for i = 1, 25 do
if cooldown then
repeat task.wait(.5) until not cooldown
else
break
end
task.wait(.5)
end
cooldown = true
Store:SetAsync(Plr.UserId,EncodedData)
print('[SERVER] Saved loadout for ' .. Plr.Name .. '!')
task.wait(2)
cooldown = false
else
Plr:Kick('Suspected of exploiting, Data could not be converted into JSON')
end
end)
Edit : If you are wondering, yes, it’s a server script. It would error if it was a local script.