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

Datastore Subcategory use?

local Data = game:GetService("DataStoreService"):GetDataStore("GeneralSaveData")
if Data.Visits:GetAsync(player.userId) == nil then --can I do this with .visits
	Data.Visits:SetAsync(player.userId,true)
	Data:GetAsync(player.userId).LastTime = tick()
	while wait(1) do
	game:GetService("TeleportService"):Teleport(36382221,player) -- tp player
	end
end

I was wondering if Data.Visits can be used as a subcategory of the datastore. Would this script do what is intended and only teleport you the first time you visit the game? Also is there any improvements that can be made to this script so it has 0 possibility of erroring.

Thanks!

1 answer

I am pretty sure that you can't do DataStore subcategories. However, in datastores, you can use tables.

Let me give you an example,

local ds = game:GetService("DataStoreService"):GetDataStore("GeneralSaveData") -- retrieve the saves
if ds:GetAsync(player.UserId) == nil then -- if he has no data saved
local table = { 
['Visits'] = true,
['LastTime'] = os.time() -- tick() saves it as your local time, os.time() is global I believe
}
ds:SetAsync(player.UserId,table) -- set his data as the table above

That'd save your data into a single table which you can retrieve with ds:GetAsync(player.UserId)[1] for visits and [2] for LastTime ect

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