Table dictionaries don't work if they are bigger than 4

hi, I was working at my Ad Sistem, I save the Ads with DataStore and HttpService but the problem is, I made a part what if the Ad Duration time is bigger than 1 day, the ad will be deleted, but the problem is if it is at the Ad 5 or bigger, it will error this:



![RobloxStudioBeta_k8xe59ur0H|316x341](upload://jrkRAkYdunqjcvkvK4VN3vrsXoH.png) 

the saving script:



function AdService:AddAd(price,id,timeStamp,PlaceId)
	local formatData = {price,id,timeStamp,PlaceId}
	local receivedData = AdStore.VideoSaving:GetAsync('VideoSavingKey4')
	if receivedData ~= nil then
	Events.OnAdAdded:Fire(price,id,os.time(),PlaceId)
	receivedData = game.HttpService:JSONDecode(receivedData)
	receivedData[tonumber((#receivedData) + 1)] = formatData
	receivedData = game.HttpService:JSONEncode(receivedData)
	AdStore.VideoSaving:SetAsync('VideoSavingKey4',receivedData)
	else
	receivedData = {}
	receivedData[tonumber((#receivedData) + 1)] = formatData
	receivedData = game.HttpService:JSONEncode(receivedData)
	AdStore.VideoSaving:SetAsync('VideoSavingKey4',receivedData)
	end
end

Probably why you shouldn’t upload error messages as images: the image isn’t loading. Please make sure to correct that so we can see the actual error information that’s occurring for your code.

I noticed also that you are using JSON encode/decode for DataStore (and even lacking use of GetService for HttpService). Don’t do this. DataStores already internally transform your information into a string value, so you’re double encoding and inflating the size of your DataStores.

Here’s how your image should’ve displayed:

RobloxStudioBeta_k8xe59ur0H

Could you please point out line 43 as you clearly haven’t given us the whole script, and it’s going to be tricky to find the error otherwise.

the line:


local TimeStamp = Ad[1][3]

and now I see I don’t put the main code:


coroutine.wrap(function()
while wait(15) do
	local FullData,Data = {},game.HttpService:JSONDecode(AdStore.VideoSaving:GetAsync('VideoSavingKey4'))
	if Data == nil then return end
	spawn(function()
	for i,Ad in ipairs(Data) do
		warn(i)
		local TimeStamp = Ad[1][3]
		warn(TimeStamp)
		if os.time() - tonumber(TimeStamp) >= 86400 then
		    
		else
			FullData[#FullData + 1] = Data
		end
	end
	spawn(function()
		Data = game.HttpService:JSONEncode(FullData)
	    AdStore.VideoSaving:SetAsync('VideoSavingKey4',Data)
	end)
  end)
end
end)()

i resolved it, the problem was with httpService