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

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

       local DataStore = game:GetService("DataStoreService"):GetDataStore('ToolSave')
game.Players.PlayerAdded:Connect(function(plr)
	local savedstuff = DataStore:GetAsync(plr.userId)
	if savedstuff ~= nil then
		for i,v in pairs(savedstuff) do
			if game.ServerStorage.Inventory:FindFirstChild(v) ~= nil then --Inventory is a folder with Weopons inside it 
				local weopon = game.ServerStorage.Inventory:FindFirstChild(v):Clone()
				weopon.Parent = plr:WaitForChild('Backpack')
				
			end
		end
	end
plr.CharacterRemoving:Connect(function()
	plr.Character.Humanoid:UnequipTools()
	
end)
end)
 
game.Players.PlayerRemoving:Connect(function(plr)
	local Table = {}
for i,v in pairs(plr.Backpack:GetChildren()) do
	table.insert(Table,v.Name) --It uses name from what I understand
	
end
if Table ~= nil then
	DataStore:SetAsync(plr.userId,Table)
end
end)

1 answer

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,

for i,v in pairs(plr.Backpack:GetChildren()) do
	table.insert(Table,v.userId) --It uses name from what I understand 
end

2 comments

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

0

you could have a table of tools and each tool has a unique number

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