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

Saving Table to datastore won't work but there are no errors?

Im trying to save a table and I did this

the script is basically supposed to print 10 more of every value but instead it prints 0 everytime

local DataStore = game:GetService("DataStoreService"):GetDataStore('TestingStore')

local Tabl = {
	Cash = 0,
	Gold =0,
	Diamonds = 0
	
	
}

function IncrementTable(Val)
	Val = Val + 10
	
end

function LoopToPrint(Table)
	for i,v in pairs(Table) do
		print(v)
	end
	
end


game.Players.PlayerAdded:Connect(function(plr)
	DataStore:GetAsync(plr.UserId)
	LoopToPrint(Tabl)
	
end)



game.Players.PlayerRemoving:Connect(function(plr)
		IncrementTable(Tabl.Cash)
		IncrementTable(Tabl.Diamonds)
		IncrementTable(Tabl.Gold)
		
		LoopToPrint(Tabl)

		
		DataStore:SetAsync(plr.UserId,Tabl)
		

end)

1 comment

0

Look into something called Pcall it run re-run the function if there was an error mainly used for datastores

1 answer

You never set Tabl to the table you loaded on join. See on line 25 where you haven't assigned the function result to a variable? That's your problem.

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