Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DS = game:GetService("DataStoreService"):GetDataStore("Backpack")
- game.Players.PlayerAdded:connect(function(player)
- function LoadInfo(character)
- wait(1)
- local key = player.userId
- local success, currentExperience = pcall(function()
- return DS:GetAsync(key)
- end)
- if not success then
- print("не сработала загрузка")
- end
- if currentExperience then
- for index, value in pairs(currentExperience) do
- if index == 1 then
- player.leaderstats.Ru.Value = value
- else if index == 2 then
- player.leaderstats.Level.Value = value
- elseif game.ReplicatedStorage.Backpack:FindFirstChild(value) then
- local Weapon = game.ReplicatedStorage.Backpack:FindFirstChild(value):Clone()
- Weapon.Parent = player:WaitForChild("Backpack")
- end
- end
- end
- end
- end
- player.CharacterAdded:Connect(LoadInfo)
- function SaveInfo(character)
- local humanoid = character:FindFirstChildOfClass("Humanoid")
- if humanoid then
- humanoid:UnequipTools()
- end
- local key = player.userId
- local Table = {}
- print("перезапись")
- table.insert(Table,player.leaderstats.Ru.Value)
- table.insert(Table,player.leaderstats.Level.Value)
- for index, value in pairs(player.Backpack:GetChildren()) do
- table.insert(Table,value.Name)
- end
- if Table then
- local success, errorMessage = pcall(function()
- DS:SetAsync(key, Table)
- end)
- if not success then
- print("не сработало сохранение")
- end
- end
- end
- player.CharacterRemoving:Connect(SaveInfo)
- end)
Advertisement
Add Comment
Please, Sign In to add comment