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

DataSave question with saving/loading tables?

Heres my script,

local carts = {
	["red"] = 1,
	["white"] = 2,
	["blue"] = 3
}

local DSService = game:GetService('DataStoreService')
local Save = DSService:GetDataStore('Carts1')

game.Players.PlayerAdded:connect(function(player)
	pcall(function()
		player:WaitForChild("PlayerGui")
		local saveData = Save:GetAsync(player.userId)
		Save:SetAsync(player.userId,carts)
		print("Done!")
		wait(4)
		if saveData then
			print("Done")
			print(saveData)
		end	
	end)
end)


Output-

23:31:09.115 - RC2 Testing was auto-saved Done! Done table: 2EF00F94

How do I get the table out of the data save using :SetAsync? All I'm getting is that output.

1 answer

To create an IntValue from all values in the table, you can go:

for i,v in pairs(saveData) do
	local val = Instance.new("IntValue")
	val.Value = v
	val.Name = i
	val.Parent = ...
end

Or to get the value for a specific colour, you can go:

print(saveData["white"]) --> 2

3 comments

0

Basically what I want the script to eventually do is get all the information in the save data, and create an IntValue for each value, the name being the string, the value being the number. How would I go about that?

0

Edited the top script for this

0

One more question, how would I do it the opposite way around? To save the players 'IntValues' how would I insert their int names and values into a table?

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