Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Scripted By: UndefinedN00B / ITestForUMAYEERIBN \\--
- local dataStores = game:GetService("DataStoreService"):GetDataStore("CashDS") -- Getting DS
- local harDS = game:GetService("DataStoreService"):GetDataStore("HarvestDS")
- local backDS = game:GetService("DataStoreService"):GetDataStore("backDS")
- local InventoryDS = game:GetService("DataStoreService"):GetDataStore("InventoryDS")
- local axDS = game:GetService("DataStoreService"):GetDataStore("AxeDS")
- local gDS = game:GetService("DataStoreService"):GetDataStore("GunDS")
- local defuldlevel = 0 -- Getting default values
- local playersLeft = 0
- local bases = workspace:WaitForChild("Bases")
- game.Players.PlayerAdded:Connect(function(player) -- When player is added
- playersLeft = playersLeft + 1 -- add value +1
- -- create a leaderstats folder
- local leaderstats = Instance.new("Folder")
- leaderstats.Name = "leaderstats"
- leaderstats.Parent = player
- -- create a values for the leaderstats
- local cash = Instance.new("IntValue")
- cash.Name = "Cash"
- cash.Value = 0
- cash.Parent = leaderstats
- local harvest = Instance.new("IntValue")
- harvest.Name = "Harvested"
- harvest.Value = 0
- harvest.Parent = leaderstats
- local plrData = Instance.new("Folder")
- plrData.Name = player.Name
- plrData.Parent = game.ServerStorage:WaitForChild("PlrData")
- local invent = Instance.new("Folder")
- invent.Name = "Inventory"
- invent.Parent = player
- local oax = Instance.new("BoolValue")
- oax.Name = "OwnsAxe"
- oax.Parent = player
- local ogu = Instance.new("BoolValue")
- ogu.Name = "OwnsGun"
- ogu.Parent = player
- local equippedVal = Instance.new("IntValue")
- equippedVal.Name = "BackEquipped"
- equippedVal.Value = 20
- equippedVal.Parent = player
- local currentStore = Instance.new("IntValue")
- currentStore.Name = "CurrentStore"
- currentStore.Parent = player
- local moneyGet = Instance.new("IntValue")
- moneyGet.Name = "MoneyGet"
- moneyGet.Parent = player
- local deb = Instance.new("BoolValue")
- deb.Name = "PlayerDebounce"
- deb.Parent = player
- local infarm = Instance.new("BoolValue")
- infarm.Name = "InFarm"
- infarm.Parent = player
- -- make nil variables for data
- local player_data
- local harves_data
- local back_data
- local invent_data
- local equipped_data
- local axe_data
- local gun_data
- -- get the data from the datatsores
- pcall(function()
- player_data = dataStores:GetAsync(player.UserId.."-cash")
- end)
- pcall(function()
- harves_data = harDS:GetAsync(player.UserId.."-harvested")
- end)
- pcall(function()
- back_data = backDS:GetAsync(player.UserId.."-backpacks")
- end)
- pcall(function()
- invent_data = InventoryDS:GetAsync(player.UserId.."-inventory")
- end)
- pcall(function()
- equipped_data = backDS:GetAsync(player.UserId.."-equipped")
- end)
- pcall(function()
- axe_data= axDS:GetAsync(player.UserId.."-axe")
- end)
- pcall(function()
- gun_data= gDS:GetAsync(player.UserId.."-gun")
- end)
- -- if the data is true, set it
- if player_data ~= nil then
- cash.Value = player_data
- print("Player Cash Loaded In.")
- else
- cash.Value = defuldlevel
- end
- if axe_data ~= nil then
- oax.Value = axe_data
- print("Player Axe Loaded.")
- else
- oax.Value = false
- print("Player Doesn't own axe")
- end
- if gun_data ~= nil then
- ogu.Value = gun_data
- print("Player Gun Loaded.")
- else
- ogu.Value = false
- print("Player Doesn't own axe")
- end
- if harves_data ~= nil then
- harvest.Value = harves_data
- print("Player Harvest Loaded In.")
- else
- harvest.Value = 0
- end
- -- loop through data and find the tool. Then duplicate it and put it in Player.plrData
- if back_data then
- for _, v in pairs(back_data) do
- if game.ServerStorage:WaitForChild("BackVals"):FindFirstChild(v) then
- local clonedV = game.ServerStorage.BackVals[v]:Clone()
- clonedV.Parent = plrData
- print(v.." has been loaded to "..player.Name)
- end
- end
- if equipped_data then
- equippedVal.Value = equipped_data
- end
- else
- print("No backpack data")
- end
- if invent_data then
- for _, v in pairs(invent_data) do
- if game.ServerStorage:WaitForChild("InventoryOb"):FindFirstChild(v) then
- local newInv = game.ServerStorage.InventoryOb[v]:Clone()
- newInv.Parent = invent
- print(v.." Has been loaded in "..player.Name.."'s Inventory.")
- end
- end
- else
- print("Nothing in Inventory")
- end
- if oax.Value ~= false then
- if not player:WaitForChild("Backpack"):FindFirstChild("Axe") then
- local axe = game.ServerStorage:WaitForChild("PlrBackpack"):WaitForChild("Axe"):Clone()
- axe.Parent = player.Backpack
- end
- end
- deb.Value = false
- end)
- local bindableEvent = Instance.new("BindableEvent") -- create a bindable event
- game.Players.PlayerRemoving:Connect(function(player)
- -- save the data with a pcall just in case some error comes up
- pcall(function()
- dataStores:SetAsync(player.UserId.."-cash", player.leaderstats.Cash.Value)
- print("Cash Has been save for "..player.Name)
- end)
- pcall(function()
- axDS:SetAsync(player.UserId.."-axe", player.OwnsAxe.Value)
- print("Axe Has Been Saved For "..player.Name)
- end)
- pcall(function()
- gDS:SetAsync(player.UserId.."-gun", player.OwnsGun.Value)
- print("Axe Gun Been Saved For "..player.Name)
- end)
- -- loop through each item and put it in table. then save the table
- pcall(function()
- local ownedBacks = game.ServerStorage.PlrData[player.Name]:GetChildren()
- local backTable = {}
- for _, v in pairs(ownedBacks) do
- table.insert(backTable, v.Name)
- end
- backDS:SetAsync(player.UserId.."-backpacks", backTable)
- if player:WaitForChild("BackEquipped").Value ~= nil then
- local equippedSaVal = player.BackEquipped
- backDS:SetAsync(player.UserId.."-equipped", equippedSaVal.Value)
- end
- print("Backpacks have been saved for "..player.Name)
- end)
- pcall(function()
- local stuff = player:WaitForChild("Inventory"):GetChildren()
- local inventTable = {}
- for _, v in pairs(stuff) do
- table.insert(inventTable, v.Name)
- end
- InventoryDS:SetAsync(player.UserId.."-inventory", inventTable)
- print(player.Name.."'s inventory has been saved.")
- end)
- pcall(function()
- harDS:SetAsync(player.UserId.."-harvested", player.leaderstats.Harvested.Value)
- print("Player Harvest Saved")
- end)
- playersLeft = playersLeft - 1
- bindableEvent:Fire()
- end)
- -- when all the players leave make sure to wait till data is saved, then shutdown the server
- game:BindToClose(function()
- while playersLeft > 0 do
- bindableEvent.Event:Wait()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement