How could i fix this? Please help please!

local DataStore = Game:GetService("DataStoreService"):GetDataStore("Storage")
Storage = {"KOS", "WOS", "Cash", "Rank", "XP"}

Game.Players.PlayerAdded:connect(function(Player)
repeat wait() until Player:FindFirstChild("leaderstats")
local Key = "user_"..Player.userId
wait(1)
for i=1, #Storage do
		if DataStore ~= nil then
		Storage[i].Value = DataStore:SetAsync(Storage[i].Name)
		DataStore:UpdateAsync(Key, function()	
		end)
		end
	end
end)

Game.Players.PlayerRemoving:connect(function(Player)
for i=1, #Storage do
		Storage[i].Value=DataStore:SetAsync(Player.Name..Storage[i].Name, Storage[i].Value)
		DataStore:UpdateAsync(Key, function()
		end)
	end
end)

DataStore:SetAsync(Player.Name..Storage[i].Name, Storage[i].Value) I added player.name to see if that might help.

How could i set a key value? (local Key = "user_"..Player.userId)) or use GetAsync? I really need this to work, please please help me!

2 comments

0

Try changing Player:WaitForChild("leaderstats") to repeat wait() until Player:findFirstChild"leaderstats" Sometimes WaitForChild breaks like that

0

Can i get help on my DataStore problem though?