I can't figure out what's wrong with it, but this server script isn't working.
local DSS = game:GetService("DataStoreService") local datastore = DSS:GetDataStore("GeneralSaveData", "Players") function generateDataKey(player) local ret = "uid_" .. player.userId return ret end function generateDataTable(player) local dataTable = {} for _, tool in ipairs(player.Backpack:GetChildren()) do table.insert(dataTable, tool.Name) end return dataTable end function saveDataForPlayer(player) local key = generateDataKey(player) local data = generateDataTable(player) datastore:SetAsync(key, data) end function inputDataToPlayer(player, data) if data then for _,T in pairs(data) do if game.ServerStorage.Weapons:FindFirstChild(T) then local wep = game.ServerStorage.Weapons:FindFirstChild(T) wep:Clone().Parent = player.StarterGear wep:Clone().Parent = player.Backpack end end end end function loadDataForPlayer(player) local key = generateDataKey(player) local data = datastore:GetAsync(key) inputDataToPlayer(player, data) end game.Players.PlayerAdded:Connect(function(player) loadDataForPlayer(player) end) game.Players.PlayerRemoving:Connect(saveDataForPlayer)
What's wrong with it and how do I fix it?