Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ____ __
- /\ _`\ /\ \
- \ \,\L\_\ _____ __ __ \_\ \ __ __
- \/_\__ \ /\ '__`\ /'__`\ /'__`\ /'_` \/\ \/\ \
- /\ \L\ \ \ \L\ \/\ __//\ __//\ \L\ \ \ \_\ \
- \ `\____\ \ ,__/\ \____\ \____\ \___,_\/`____ \
- \/_____/\ \ \/ \/____/\/____/\/__,_ /`/___/> \
- \ \_\ /\___/
- \/_/ \/__/
- -- Speedy Systems --
- --]]
- local DataStoreService = game:GetService("DataStoreService")
- local myDataStore = DataStoreService:GetDataStore("myDataStore")
- game.Players.PlayerAdded:Connect(function(plr)
- local leaderstats = Instance.new("Folder")
- leaderstats.Name = "leaderstats"
- leaderstats.Parent = plr
- local otherData = Instance.new("Folder")
- otherData.Name = "otherData"
- otherData.Parent = plr
- local Coins = Instance.new("IntValue")
- local Logs = Instance.new("IntValue")
- local TreesCut = Instance.new("IntValue")
- local LogSpace = Instance.new("IntValue")
- local currentDoors = Instance.new("Folder")
- --// Add comas
- function addComas(str)
- return #str % 3 == 0 and str:reverse():gsub("(%d%d%d)", "%1,"):reverse():sub(2) or str:reverse():gsub("(%d%d%d)", "%1,"):reverse()
- end
- Coins.Changed:Connect(function()
- plr.PlayerGui:WaitForChild("MainGui").Stats.Coins.Icon.Amount.Text = addComas(tostring(Coins.Value))
- end)
- Logs.Changed:Connect(function()
- if Logs.Value <= LogSpace.Value then
- plr.PlayerGui:WaitForChild("MainGui").Stats.Logs.AmountV.Value = addComas(tostring(Logs.Value))
- else
- Logs.Value = addComas(tostring(Logs.Value))
- end
- end)
- Coins.Name = "💰Coins"
- Logs.Name = "🌲Logs"
- TreesCut.Name = "🌳Trees Cut"
- LogSpace.Name = "LogSpace"
- currentDoors.Name = "currentDoors"
- Coins.Parent = leaderstats
- LogSpace.Parent = otherData
- Logs.Parent = leaderstats
- TreesCut.Parent = leaderstats
- currentDoors.Parent = plr
- local data1
- local data2
- local data3
- local data4
- local data5
- local success, errormessage = pcall(function()
- data1 = myDataStore:GetAsync(plr.UserId.."-Coins")
- data2 = myDataStore:GetAsync(plr.UserId.."-Logs")
- data3 = myDataStore:GetAsync(plr.UserId.."-TreesCut")
- data4 = myDataStore:GetAsync(plr.UserId.."-LogSpace")
- data5 = myDataStore:GetAsync(plr.UserId.."-currentDoors")
- end)
- if data1 and data2 and data3 and data4 and data5 then
- Coins.Value = data1
- TreesCut.Value = data3
- LogSpace.Value = data4
- Logs.Value = data2
- Logs.Value = Logs.Value + 1
- Logs.Value = Logs.Value - 1
- currentDoors = data5
- else
- print("An error occurred while getting player's data!")
- warn(errormessage)
- end
- if LogSpace.Value == 0 then
- LogSpace.Value = 10
- end
- local ii = 1
- local u = workspace.Earth.Biomes.BiomeDoors[myDataStore:GetAsync(plr.UserId.."-currentDoors")]:WaitForChild("Num").Value
- for i, v in pairs (workspace.Earth.Biomes.BiomeDoors:GetChildren()) do
- if ii <= u then
- if v.Num.Value == ii and v.Num.Value ~= u then
- if v.Num.Value == nil then print("nil") end
- game.ReplicatedStorage.Remotes.areaHandler:FireClient(plr, v.Name)
- ii = ii + 1
- elseif v.Num.Value == u and v.Num.Value == ii then
- game.ReplicatedStorage.Remotes.areaHandler:FireClient(plr, v.Name)
- ii = ii + 1
- end
- end
- end
- end)
- game.Players.PlayerRemoving:Connect(function(plr)
- local success, errormessage = pcall(function()
- myDataStore:SetAsync(plr.UserId.."-Coins", plr.leaderstats["💰Coins"].Value)
- myDataStore:SetAsync(plr.UserId.."-Logs", plr.leaderstats["🌲Logs"].Value)
- myDataStore:SetAsync(plr.UserId.."-TreesCut", plr.leaderstats["🌳Trees Cut"].Value)
- myDataStore:SetAsync(plr.UserId.."-LogSpace", plr.otherData.LogSpace.Value)
- myDataStore:SetAsync(plr.UserId.."-currentDoors", plr.currentDoors.Value)
- end)
- if success then
- print("Data was successfully saved!")
- else
- print("An error occurred!")
- warn(errormessage)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment