DataStore Error

Hi! I recently came back to roblox and am going through an old game and going to finish it as I gave up on it. Anyways, I am having to redo a lot of stuff and I need to add the name of a border that is bought to a table.

local remoteEvent = game.ReplicatedStorage.BuyArea
local areaDataStore = game:GetService("DataStoreService"):GetDataStore("BorderSave")

for _, border in pairs(workspace.Borders:GetChildren()) do
	if border:IsA("Part") then
		border.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				print(border.Name.." was touched!")
				local character = hit.Parent
				local player = game.Players:GetPlayerFromCharacter(character)
				player.AreaSelected.Value = border.Name
				player.PlayerGui.BuyArea.Enabled = true
				local price = game.Workspace.Borders.Area7Border.Price
				player.PlayerGui.BuyArea.Body.TextBox.TextLabel.Text = "Would you like to buy " .. dataScript[border.Name].." for ".. workspace.Borders[border.Name].Price.Value.."?"
			end
		end)
	end
end

local boughtData = {}

game:GetService("Players").PlayerRemoving:Connect(function(player) -- Checking if player is leaving game
	local Success, Error = pcall(function()
		return game:GetService("DataStoreService"):GetDataStore("BorderSave"):SetAsync(player.UserId.."Borders", boughtData)
		-- Setting the data for inventory for the player
	end)
	if Error then
		warn(Error) -- Showing there was error (Can also keep in log to fix)
	end
end)


remoteEvent.OnServerEvent:Connect(function(player, border)
	if player.leaderstats.Coins.Value >= workspace.Borders[border].Price.Value then
		local Success, Error = pcall(function()
			table.insert(boughtData, 1, border)
			return game:GetService("DataStoreService"):GetDataStore("BorderSave"):SetAsync(player.UserId.."Borders", boughtData)
			-- Setting the data for inventory for the player
		end)
		if Error then
			warn(Error) -- Showing there was error (Can also keep in log to fix)
		end
	else
		print("Not Enough Money!")
	end
end)

I’m pretty sure its making the table but I am not sure if it is adding anything INTO the table.

1 Like

Im pretty sure its because you defined the table with nothing in it, and when you SetAsnyc, it saves that same empty table

			table.insert(boughtData, 1, border)
			return game:GetService("DataStoreService"):GetDataStore("BorderSave"):SetAsync(player.UserId.."Borders", boughtData)
			-- Setting the data for inventory for the player
		end)

But didn’t I use table.insert right before? :confounded:

1 Like

Can you show me the error???

1 Like

There was no error, im just not sure its working

1 Like

Try enabling these options in

Home > Game Settings > Security

If it won’t work try making game private to public.

1 Like

Ok, I used a datastore plug-in, it showed that there was a table but it was empty. :confused:

1 Like

yeah try using my steps, because you maybe not enabled that api and studio will not access to the datastore api until you turn it on!

1 Like

No, I double checked just now they were on.

try making game private to public?

1 Like

I thinking I am starting to make it work, thanks for your help!

No problem!!! can you mention what was the problem tho?

1 Like