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

Am I on track with this table saving/loading script?

So I made this really simple script that uses datastore to load a table (or create a new one if there isn't one to load) for a player when they join & then save it when they leave, I just wanted to know if am on the right track with it.

local DSS = game:GetService("DataStoreService")
local PltngConfig = DSS:GetDataStore("PlatingConfig")

game.Players.PlayerAdded:connect(function(player)
	PlatingConfig = PltngConfig:GetAsync(player.userid) or {}
	
end)

game.Players.PlayerRemoving:connect(function(player)
	PltngConfig:SetAsync(player.userid, PlatingConfig)
	
end)

1 answer

Mostly but one thing is coming to me. At line 5 the or {} what's the point of it? All I see it could do is raise a error. If you can reply I'll reply soon at the max 10 hours. However if its not night for me I will prob reply a lot sooner then 10 hours.

Update: I was told what the or {} is for so your on track with it.

3 comments

0

It is meant to be that if the GetAsync returns nil (because the player doesn't have any saved data) then it makes a new table

0

Oh then your on track

0

I edited the answer.

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