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

Do I use the player's userid as a scope for datastores?

Do I just put the player's user id as a scope? And btw when I make a library to store the player's data and update it and then save it, do I just do this:

local currenctSession = {}
currentSession = *datastore*:GetAsync

(i mean thats how you store the players saved datastore into a dictionary, right?)

1 answer

✓ Accepted answer

1st No you do not use the players UserId for the scope that would be like making a new file per player. The point of a database is to keep data in its tables not making one table per player.

2nd Thats not how you would make a ibrary to store the player's data. You would just use a module to setup the players data then use functions to set / get data.

Lastly you will need to look into how to save player data.

saving player data

Example of the basic idea of player stats object:-

local function newPlayer(plrUerId)

	-- load player stats in or use default calue
	
	local f = {} -- the return functions
	function f.Save()
		-- save player data
	end

	function f.Get() -- some value

	end
	
	return f
end

-- script
local plrData = {}

game.Players.PlayerAdded:Connect(function(plr)
	plrData[plr] =  newPlayer(plr.UserId) -- player stats obj
end)

game.Players.PlayerRemoving:Connect(function(plr)
	if plrData[plr]  then
		plrData[plr].Save() -- call the save player function in the obj
		plrData[plr] = nil -- remove player obj
	end	
end)

I hope this help.

2 comments

0

There you go. An upvote. lol

0

Thank you.

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