Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This datastore that saves a table doesn't work, can someone help me please?

This is my code:

local purchasedfolder = game.Workspace.PurchasedValues
local HttpService = game:GetService("HttpService")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TableTestDataStore")
game.Players.PlayerAdded:Connect(function(player)
	local key = player.Name.."-"..player.UserId
	local encodedData = DataStore:GetAsync(key)
	local data = HttpService:JSONDecode(encodedData)
end)
game.Players.PlayerRemoving:Connect(function(player)
	local data  = {
    	purchasedfolder.Purchasedbmw.Value,
	    purchasedfolder.Purchasedgtr.Value, 
	    purchasedfolder.Purchasedhoon.Value,
	    purchasedfolder.Purchasedmc.Value,
	    purchasedfolder.Purchasedpor.Value,
	    purchasedfolder.Purchaseds13.Value
	}
	local key = player.Name.."-"..player.UserId
	local normalData = HttpService:JSONEncode(data)
	DataStore:SetAsync(key,normalData)
end)

1 answer

✓ Accepted answer

It's because you got the table from the datastore, but you still need to set the values to the values of the table. Fixed script:

local purchasedfolder = game.Workspace.PurchasedValues
local HttpService = game:GetService("HttpService")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TableTestDataStore")
game.Players.PlayerAdded:Connect(function(player)
	local key = player.Name.."-"..player.UserId
	local encodedData = DataStore:GetAsync(key)
	local data = HttpService:JSONDecode(encodedData)
	-- Set the values from the decoding
	purchasedfolder.Purchasedbmw.Value = data[1]
	purchasedfolder.Purchasedgtr.Value = data[2]
	purchasedfolder.Purchasedhoon.Value = data[3]
	purchasedfolder.Purchasedmc.Value = data[4]
	purchasedfolder.Purchasedpor.Value = data[5]
	purchasedfolder.Purchaseds13.Value = data[6]
end)
game.Players.PlayerRemoving:Connect(function(player)
	local data  = {
    	purchasedfolder.Purchasedbmw.Value,
	    purchasedfolder.Purchasedgtr.Value, 
	    purchasedfolder.Purchasedhoon.Value,
	    purchasedfolder.Purchasedmc.Value,
	    purchasedfolder.Purchasedpor.Value,
	    purchasedfolder.Purchaseds13.Value
	}
	local key = player.Name.."-"..player.UserId
	local normalData = HttpService:JSONEncode(data)
	DataStore:SetAsync(key,normalData)
end)

I hope this fixed your problem!

1 comment

0

Ok ty.

This discussion is preserved as it was. New answers, comments, and votes are closed.