BumpyPlayz

My Porfolio?

Jul 27th, 2020 (edited)
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.06 KB | None | 0 0
  1. So this is my YouTube Channel - https://www.youtube.com/channel/UCqvurGZT7Motn0ivduSgdxQ
  2.  
  3. Link to a game in which I am head programmer - https://web.roblox.com/games/5531544242/INF-PETS-Chaos-Clicker
  4.  
  5.  
  6. A data handler from my upcomming game -
  7.  
  8. local module = {}
  9. local equiper = require(script.Parent:WaitForChild("EquipHandler"))
  10. local gloablstatshandler = require(game.ServerScriptService:WaitForChild("GloablLeaderboards"):WaitForChild("GlobalLeaderbaordsHandler"))
  11.  
  12.  
  13. local function newFolder(parent, name)
  14.     local new = Instance.new("Folder", parent)
  15.     new.Name = name
  16.     return new
  17. end
  18.  
  19. local function newValue(parent, name, typ, value)
  20.     local new = Instance.new(typ, parent)
  21.     new.Name = name
  22.     new.Value = value
  23.     return new
  24. end
  25.  
  26. function module.exportData(datastore, player)
  27.     local playerData = datastore:GetAsync(player.UserId) or {}
  28.     playerData.Settings = playerData.Settings or {}
  29.    
  30.     local leaderstats = newFolder(player, "leaderstats")
  31.     local data = newFolder(player, "data")
  32.    
  33.     local views, coins, streamer = newValue(leaderstats, "Viewers", "StringValue", playerData.views or 0), newValue(leaderstats, "Coins", "StringValue", playerData.coins or 0), newValue(leaderstats, "Streamer", "StringValue", playerData.streamer or 'Lame Streamer')
  34.  
  35.    
  36.     local userSettings = newFolder(data, "userSettings")
  37.    
  38.     for _,setting in ipairs(game.StarterGui:WaitForChild("Settings"):WaitForChild("ImageLabel"):WaitForChild("ScrollingFrame"):GetChildren()) do
  39.         if setting:IsA("ImageLabel") and not setting:FindFirstChild("NO_SAVE") then
  40.             local newEntry = newValue(userSettings, setting.Name, "BoolValue", playerData.Settings[setting.Name] or false)
  41.         end
  42.     end
  43.    
  44.     local laptops = newFolder(data, "laptops")
  45.     local backpacks = newFolder(data, "backpacks")
  46.     local classes = newFolder(data, "classes")
  47.     local areas = newFolder(data, "areas")
  48.    
  49.     playerData.laptops = playerData.laptops or {
  50.         "Broken Laptop"
  51.     }
  52.     playerData.backpacks = playerData.backpacks or {
  53.         "Broken Bandwidth"
  54.     }
  55.     playerData.classes = playerData.classes or {
  56.         "Lame Streamer"
  57.     }
  58.     playerData.areas = playerData.areas or {}
  59.    
  60.    
  61.     local currentLaptop = newValue(data, "currentLaptop", "StringValue", playerData.currentLaptop or "Broken Laptop")
  62.     local currentBackpack = newValue(data, "currentBackpack", "StringValue", playerData.currentBackpack or "Broken Bandwidth")
  63.     local currentClass = newValue(data, "currentClass", "StringValue", playerData.currentClass or "Lame Streamer")
  64.    
  65.     --parse things
  66.     for _,laptop in ipairs(playerData.laptops) do
  67.         newValue(laptops, laptop, "StringValue", "")
  68.     end
  69.     for _,backpack in ipairs(playerData.backpacks) do
  70.         newValue(backpacks, backpack, "StringValue", "")
  71.     end
  72.     for _,class in ipairs(playerData.classes) do
  73.         newValue(classes, class, "StringValue", "")
  74.     end
  75.     for _,area in ipairs(playerData.areas) do
  76.         newValue(areas, area, "StringValue", "")
  77.     end
  78.    
  79.     local importantvalues = newFolder(player, "ImportantValues")
  80.     local backpacksize = newValue(importantvalues, "BackpackSize", "StringValue", 1)
  81.     local LaptopRate = newValue(importantvalues, "LaptopRate", "NumberValue", 1)
  82.     local ClassBoost = newValue(importantvalues, "ClassBoost", "NumberValue", 1)
  83.     local ClassBoost = newValue(importantvalues, "SpeedBoost", "NumberValue", 1)
  84.    
  85.     equiper.equiplaptop(player, player.data.currentLaptop.Value or "Broken Laptop")
  86.     equiper.equipbackpack(player, player.data.currentBackpack.Value or "Broken Bandwidth")
  87.     equiper.equipclass(player, player.data.currentClass.Value or "Lame Streamer")
  88.    
  89.     local viewval = views.Value
  90.     local coinval = coins.Value
  91.    
  92.     views.Changed:Connect(function()
  93.         local change = views.Value - viewval
  94.         viewval =  views.Value
  95.         if change >0 then
  96.             gloablstatshandler.update(player, 'Bandwidth', change)
  97.         end
  98.     end)
  99.    
  100.    
  101.     coins.Changed:Connect(function()
  102.         local change = coins.Value - coinval
  103.         coinval =  coins.Value
  104.         if change >0 then
  105.             gloablstatshandler.update(player, 'MostCoins', change)
  106.         end
  107.     end)
  108.    
  109.     player.CharacterAdded:Connect(function()
  110.         equiper.equiplaptop(player, player.data.currentLaptop.Value or "Broken Laptop")
  111.         equiper.equipbackpack(player, player.data.currentBackpack.Value or "Broken Bandwidth")
  112.         equiper.equipclass(player, player.data.currentClass.Value or "Lame Streamer")
  113.     end)
  114. end
  115.  
  116. function module.saveData(datastore, player)
  117.     local formedData = {
  118.         Settings = {},
  119.         laptops = {},
  120.         backpacks = {},
  121.         classes = {},
  122.         areas = {}
  123.     }
  124.    
  125.     local leaderstats = player:WaitForChild("leaderstats")
  126.     local data = player:WaitForChild("data")
  127.    
  128.     local laptops = data:WaitForChild("laptops")
  129.     local backpacks = data:WaitForChild("backpacks")
  130.     local classes = data:WaitForChild("classes")
  131.     local areas = data:WaitForChild("areas")
  132.    
  133.     for _, laptop in ipairs(laptops:GetChildren()) do
  134.         formedData.laptops[#formedData.laptops+1] = laptop.Name
  135.     end
  136.     for _, backpack in ipairs(backpacks:GetChildren()) do
  137.         formedData.backpacks[#formedData.backpacks+1] = backpack.Name
  138.     end
  139.     for _, class in ipairs(classes:GetChildren()) do
  140.         formedData.classes[#formedData.classes+1] = class.Name
  141.     end
  142.     for _, area in ipairs(areas:GetChildren()) do
  143.         formedData.areas[#formedData.areas+1] = area.Name
  144.     end
  145.    
  146.     formedData.views = tonumber(leaderstats:WaitForChild("Viewers").Value)
  147.     formedData.coins = tonumber(leaderstats:WaitForChild("Coins").Value)
  148.     formedData.streamer = leaderstats:WaitForChild("Streamer").Value
  149.    
  150.     formedData.currentLaptop = data:WaitForChild("currentLaptop").Value
  151.     formedData.currentBackpack = data:WaitForChild("currentBackpack").Value
  152.     formedData.currentClass = data:WaitForChild("currentClass").Value
  153.    
  154.     for _,setting in ipairs(data:WaitForChild("userSettings"):GetChildren()) do
  155.         formedData.Settings[setting.Name] = setting.Value
  156.     end
  157.     datastore:SetAsync(player.UserId, formedData)
  158.     print("saved data for "..player.Name)
  159.     return formedData
  160. end
  161.  
  162. function module.ownsBackpack(player, backpackName)
  163.     for _,backpack in ipairs(player:WaitForChild("data"):WaitForChild("backpacks"):GetChildren()) do
  164.         if backpack.Name == backpackName then
  165.             return true
  166.         end
  167.     end
  168.     return false
  169. end
  170.  
  171. return module
  172.  
Advertisement
Add Comment
Please, Sign In to add comment