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

Inserting IntValues into a table?

Here's 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
			for i,v in pairs(saveData) do
				Int = Instance.new("IntValue")
				Int.Name = i
				Int.Value = v
				Int.Parent = game.Workspace.Test
			end

		end	
	end)
end)

So basically what I want to do is when a player joins it gets the table of values and inserts them into an IntValue in the player (Right now its going to workspace for testing purposes, will be in the player). My question is if the carts table was empty how would I insert the IntValues into the table to save? I tried,

local carts = {

}

for i,v in pairs(game.Workspace.Test:GetChildren()) do
	table.insert(carts,i,v)
end

It returned that the game cannot save array values, I do not know how to change that.

1 answer

✓ Accepted answer

Try:

for _, v in pairs(workspace.Test:GetChildren()) do
	carts[v.Name] = v.Value
end

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