Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService('Players')
- local Storage = game:GetService('ServerStorage')
- local DataHandler = require(script['DataHandler'])
- local Create = function(class, parent)
- local instance = Instance.new(class);
- return function(props)
- for property, value in next, (props) do
- if (property ~= 'Parent') and (typeof(value) ~= 'Instance') then
- local suc, err = pcall(function()
- instance[property] = value
- end)
- elseif (property == 'Parent') then
- parent = value
- end
- end
- if parent and (typeof(parent) == 'Instance') then
- instance['Parent'] = parent
- end
- return instance
- end
- end
- local Data = DataHandler '[A1-OUR-LORD-AND-SAVIOUR] 152';
- local OldStats = DataHandler 'LeaderstatsDataStore';
- local OldTools = DataHandler 'WeaponDataStore';
- local Blacklist = {
- Membership = true;
- }
- local function Enter(Client)
- local Key = Data.parse('[INF]:-', Client, 'UserId')
- local GStored, Stored = Data.get(Key)
- local Server = Data.proxy[Key]
- if not Stored and not Server then
- local GLevel, Level = OldStats.get('level_' .. Client['UserId'])
- local GXP, XP = OldStats.get('xp_' .. Client['UserId'])
- local GGold, Gold = OldStats.get('gold_' .. Client['UserId'])
- local GRebirth, Rebirth = OldStats.get('rebirth_' .. Client['UserId'])
- Data.set(Key, {
- Level = (GLevel and Level) or 1;
- XP = (GXP and XP) or 0;
- Gold = (GGold and Gold) or 0;
- Rebirth = (GRebirth and Rebirth) or 0;
- Tools = (function()
- local IHAVENTDIED, STRANDOFHAIR = OldTools.get("user_" .. Client['UserId'])
- local AHHHHHH = {}
- if IHAVENTDIED and STRANDOFHAIR then
- for PULL = 1, #STRANDOFHAIR do
- AHHHHHH[STRANDOFHAIR[PULL]] = true
- end
- end
- return AHHHHHH
- end)();
- })
- elseif not Stored and Server then
- Data.set(Server)
- elseif Stored then
- Data.proxy[Key] = Stored
- end
- --local GL = Client:WaitForChild("IsGPLoaded")
- --local DL = Client:WaitForChild("IsDataLoaded")
- local Loaded = Data.proxy[Key]
- local Leader = Create('Folder', Client){
- Name = 'leaderstats';
- }
- Create('IntValue', Leader){
- Name = 'Level';
- Value = Loaded.Level
- }
- Create('NumberValue', Leader){
- Name = 'XP';
- Value = Loaded.XP
- }
- Create('NumberValue', Leader){
- Name = 'Gold';
- Value = Loaded.Gold
- }
- Create('IntConstrainedValue', Leader){
- Name = 'Rebirth';
- MaxValue = 99;
- Value = Loaded.Rebirth
- }
- --repeat wait() until GL.Value
- local Tools = (function()
- local t= {}
- for __, Folder in next, (Storage:WaitForChild('Items'):GetChildren()) do
- if not Blacklist[Folder['Name']] then
- for __, tool in next, (Folder:GetChildren()) do
- t[#t + 1] = tool
- end
- end
- end
- return t
- end)()
- for Name, Enabled in next, (Loaded.Tools) do
- if Enabled then
- for index = 1, #Tools do
- local Tool = Tools[index]
- if (Name == Tool['Name']) and not (Client.StarterGear:FindFirstChild(Tool['Name'])) then
- Tool:Clone().Parent = Client.StarterGear
- end
- end
- end
- end
- --DL.Value = true
- if Client.Character then
- Client:LoadCharacter()
- end
- end
- local function Exit(Client)
- local Key = Data.parse('[INF]:-', Client, 'UserId')
- local Server = Data.proxy[Key]
- if Server then
- local Names = {}
- table.foreach(Client.StarterGear:GetChildren(),
- function(_, Name)
- local Obj = Storage.Items:FindFirstChild(tostring(Name), true)
- local Ignore do
- if Obj and Blacklist[Obj.Parent['Name']] then
- Ignore = true
- end
- end
- if not Ignore then
- Names[tostring(Name)] = true
- end
- end
- )
- local Leader = Client:WaitForChild('leaderstats')
- Data.set(Key, {
- Tools = Names;
- Level = Leader.Level.Value;
- XP = Leader.XP.Value;
- Gold = Leader.Gold.Value;
- Rebirth = Leader.Rebirth.Value;
- })
- end
- Data.proxy[Key] = nil
- end
- for __, Player in next, (Players:GetPlayers()) do
- Enter(Player)
- end
- Players.PlayerAdded:Connect(Enter)
- Players.PlayerRemoving:Connect(Exit)
- game:BindToClose(function()
- for __, Client in next, (Players:GetPlayers()) do
- spawn(function()
- local Key = Data.parse('[INF]:-', Client, 'UserId')
- local Server = Data.proxy[Key]
- if Server then
- local Names = {}
- table.foreach(Client.StarterGear:GetChildren(),
- function(_, Name)
- local Obj = Storage.Items:FindFirstChild(tostring(Name), true)
- local Ignore do
- if Obj and Blacklist[Obj.Parent['Name']] then
- Ignore = true
- end
- end
- if not Ignore then
- Names[tostring(Name)] = true
- end
- end
- )
- local Leader = Client:WaitForChild('leaderstats')
- Data.set(Key, {
- Tools = Names;
- Level = Leader.Level.Value;
- XP = Leader.XP.Value;
- Gold = Leader.Gold.Value;
- Rebirth = Leader.Rebirth.Value;
- })
- end
- end)
- end
- end)
- while wait(300) do
- warn('AUTO SAVE')
- for __, Client in next, (Players:GetPlayers()) do
- spawn(function()
- local Key = Data.parse('[INF]:-', Client, 'UserId')
- local Server = Data.proxy[Key]
- if Server then
- local Names = {}
- table.foreach(Client.StarterGear:GetChildren(),
- function(_, Name)
- local Obj = Storage.Items:FindFirstChild(tostring(Name), true)
- local Ignore do
- if Obj and Blacklist[Obj.Parent['Name']] then
- Ignore = true
- end
- end
- if not Ignore then
- Names[tostring(Name)] = true
- end
- end
- )
- local Leader = Client:WaitForChild('leaderstats')
- Data.set(Key, {
- Tools = Names;
- Level = Leader.Level.Value;
- XP = Leader.XP.Value;
- Gold = Leader.Gold.Value;
- Rebirth = Leader.Rebirth.Value;
- })
- end
- end)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement