Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

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.

0
There you go. An upvote. lol User#21908 42 — 5y
0
Thank you. radusavin366 617 — 5y
Ad

Answer this question