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

Is it a good idea to make a Name the key of DataStore? Is there any other safer way than this?

Asked by 6 years ago
01       local DataStore = game:GetService("DataStoreService"):GetDataStore('ToolSave')
02game.Players.PlayerAdded:Connect(function(plr)
03    local savedstuff = DataStore:GetAsync(plr.userId)
04    if savedstuff ~= nil then
05        for i,v in pairs(savedstuff) do
06            if game.ServerStorage.Inventory:FindFirstChild(v) ~= nil then --Inventory is a folder with Weopons inside it
07                local weopon = game.ServerStorage.Inventory:FindFirstChild(v):Clone()
08                weopon.Parent = plr:WaitForChild('Backpack')
09 
10            end
11        end
12    end
13plr.CharacterRemoving:Connect(function()
14    plr.Character.Humanoid:UnequipTools()
15 
View all 28 lines...

1 answer

Log in to vote
1
Answered by
farizarps 132
6 years ago

Players can change their name so using a name as a key is a bad idea. if a player changes their name when they rejoin your game it would make a new datastore for them as if they are a new player.

A better alternative is to use a players userId. every player is assigned a unique userId that never changes so you would be better off using it.

to use it is simply player.userId and in your case,

1for i,v in pairs(plr.Backpack:GetChildren()) do
2    table.insert(Table,v.userId) --It uses name from what I understand
3end
0
Thats not what I mean, I need a way to classify the Tools in the Tables and Inventory because Just one change = wipeout of data User#22788 5 — 6y
0
you could have a table of tools and each tool has a unique number farizarps 132 — 6y
Ad

Answer this question