Advertisement
qsenko1

StandsSystem

Feb 27th, 2022
1,330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.52 KB | None | 0 0
  1. local http = game:GetService("HttpService")
  2. local baseUrl = "https://catalog.roproxy.com/v1/search/items/details?Category=3&Subcategory=13&Limit=30&CreatorName=%s&cursor=%s"
  3. local ProximityPromptService = game:GetService("ProximityPromptService")
  4. local Stands = game.Workspace.ShopStands
  5. local ShopEvent = game.ReplicatedStorage.ShopEvent
  6. local ProximityPromptUpdater = game.ReplicatedStorage.ProximityPromptUpdater
  7. local UnclaimEvent = game.ReplicatedStorage.UnclaimEvent
  8. local RefreshEvent = game.ReplicatedStorage.RefreshEvent
  9. local StandColorChangeEvent = game.ReplicatedStorage.StandColorChangeEvent
  10. local debounce = true
  11. local atestnumber = 0
  12.  
  13. local function getUserGeneratedTShirtsRecursive(username, tshirts, cursor)
  14.     tshirts = tshirts or {}
  15.     cursor = cursor or ""
  16.     local requestUrl = baseUrl:format(username, cursor)
  17.     local success, result = pcall(function()
  18.     --  print(http:GetAsync(requestUrl))
  19.         return http:GetAsync(requestUrl)
  20.     end)
  21.  
  22.     if success then
  23.         if result then
  24.             local success2, result2 = pcall(function()
  25.             --  print(http:JSONDecode(result))
  26.             --  print(http:JSONEncode(result)) --this or the other
  27.                 return http:JSONDecode(result)
  28.             end)
  29.  
  30.             if success2 then
  31.                 if result2 then
  32.                     for _, tshirt in ipairs(result2.data) do
  33.                     --  print(tshirt)
  34.                         table.insert(tshirts, tshirt.id)       
  35.                     --  table.insert(tshirts, tshirt.price)
  36.                     end
  37.  
  38.                     cursor = result2.nextPageCursor
  39.                     if cursor then
  40.                         return getUserGeneratedTShirtsRecursive(username, tshirts, cursor)
  41.                     else
  42.                         return tshirts
  43.                     end
  44.                 end
  45.             else
  46.                 warn(result)
  47.             end
  48.         end
  49.     else
  50.         warn(result)
  51.     end
  52. end
  53.  
  54. local function getUserGeneratedTShirtsPrices(username, tshirts, cursor)
  55.     tshirts = tshirts or {}
  56.     cursor = cursor or ""
  57.     local requestUrl = baseUrl:format(username, cursor)
  58.     local success, result = pcall(function()
  59.         --  print(http:GetAsync(requestUrl))
  60.         return http:GetAsync(requestUrl)
  61.     end)
  62.  
  63.     if success then
  64.         if result then
  65.             local success2, result2 = pcall(function()
  66.             --  print(http:JSONDecode(result))
  67.             --  print(http:JSONEncode(result))
  68.                 return http:JSONDecode(result)
  69.             end)
  70.  
  71.             if success2 then
  72.                 if result2 then
  73.                     for _, tshirt in ipairs(result2.data) do
  74.                         table.insert(tshirts, tshirt.price)
  75.                     end
  76.  
  77.                     cursor = result2.nextPageCursor
  78.                     if cursor then
  79.                         return getUserGeneratedTShirtsRecursive(username, tshirts, cursor)
  80.                     else
  81.                         return tshirts
  82.                     end
  83.                 end
  84.             else
  85.                 warn(result)
  86.             end
  87.         end
  88.     else
  89.         warn(result)
  90.     end
  91. end
  92.  
  93. local dictionary = {}
  94.  
  95. game.Players.PlayerAdded:Connect(function(Player)
  96. --  print(Player)
  97.     local PlayerStandCheck = Instance.new("BoolValue")
  98.     PlayerStandCheck.Parent = Player
  99.     PlayerStandCheck.Value = false
  100.     PlayerStandCheck.Name = "PlayerStandCheck"
  101.     for i,stands in pairs(Stands:GetDescendants()) do
  102.         if stands:IsA("Model") and stands.Name == "ShopStand" then
  103.             stands:FindFirstChild("PricePart").Attachment.ProximityPrompt.Triggered:Connect(function(Player)
  104.                 if stands:FindFirstChild("Owned").Value == false and stands:FindFirstChild("PlayerName").Value == "" and Player:FindFirstChild("PlayerStandCheck").Value ~= true then -- and debounce
  105.                     Player:FindFirstChild("PlayerStandCheck").Value = true
  106.                     stands:FindFirstChild("Owned").Value = true
  107.                     stands:FindFirstChild("PlayerName").Value = Player.Name
  108.                     stands:FindFirstChild("DescriptionPart").SurfaceGui.PlayerName.Text = Player.Name  .. "'s stand"
  109.                     stands:FindFirstChild("DescriptionPart").SurfaceGui.PriceRaised.Text = Player.leaderstats["Raised 💰"].Value .. " raised"
  110.                     stands:FindFirstChild("DescriptionPart").SurfaceGui.PriceRaised.Visible = true
  111.                     local Song = "Level Up"
  112.                     ShopEvent:FireClient(Player,Song)
  113.                     ProximityPromptUpdater:FireAllClients(Player)
  114.                     wait(.5)
  115.                     local username = Player.Name --"ignaury"
  116.                     local userTShirts = getUserGeneratedTShirtsRecursive(username)
  117.                 --  print(userTShirts) -- it brings a table id thingy
  118.                 --  print(#userTShirts) --3
  119.                 --  print(table.concat(userTShirts, " "))
  120.                     wait(.1)
  121.                     local price = getUserGeneratedTShirtsPrices(username)
  122.             --      print(table.concat(price, " "))
  123.                  -- local randomnumbers = {(unpack(price))}
  124.                 --  print(randomnumbers)
  125.             --      print(price[i])
  126.             --      print(price[1])
  127.             --      print(price[2])
  128.             --      print(price[0])
  129.                     --print(price)     
  130.                     task.wait(.5)
  131.                    
  132.                     local number = #userTShirts or nil
  133.                 --  print(userTShirts)
  134.                 --  print(userTShirts[1])
  135.                 --  print(userTShirts[2])
  136.                    
  137.                     local prices = #price
  138.                     if #userTShirts ~= 0 and #userTShirts ~= nil then
  139.                         stands:FindFirstChild("PricePart").SurfaceGui.Enabled = true
  140.                         --print(userTShirts.price[i])
  141.                         --print(price == userTShirts)  
  142.                         local TextLocation = game:GetService("ServerStorage")
  143.                         local ButtonFolder = Instance.new("Folder")
  144.                         ButtonFolder.Parent = TextLocation
  145.                         ButtonFolder.Name = Player.Name
  146.                         for i,stands in pairs(Stands:GetDescendants()) do
  147.                            if stands:IsA("Model") and stands.Name == "ShopStand" then
  148.                               if stands:FindFirstChild("Owned").Value == true and stands:FindFirstChild("PlayerName").Value == Player.Name and Player:FindFirstChild("PlayerStandCheck").Value == true then
  149.                             for i = 1, number do
  150.                     --      print("Cloning depending on the number")       
  151.                             local TextClone = TextLocation.ButtonForClone.TextButton:Clone()
  152.                             TextClone.Parent = ButtonFolder                    
  153.                             --TextClone.Parent = stands:FindFirstChild("PricePart").SurfaceGui.Frame.ScrollingFrame
  154.                             local PriceText = TextClone    
  155.                         --  prices += #price
  156.                         --  PriceText.Text = price
  157.                         --local randomnumber = unpack(userTShirts)
  158.             --[[            for i, item in pairs (userTShirts) do  
  159.                             print(item)
  160.                             print(i)
  161.                         --  PriceText.Text = item
  162.                             if i == #userTShirts then
  163.                                 break
  164.                             end            
  165.                         end --]]   
  166.                                         atestnumber = atestnumber + 1
  167.                         --              print(atestnumber)
  168.                                         PriceText.Text = price[atestnumber] .. "$"
  169.                                         PriceText.Price.Value = price[atestnumber]
  170.                                         PriceText:FindFirstChild("id").Value = userTShirts[atestnumber]
  171.                                         --PriceText.Name = "ImageButton" .. atestnumber
  172.                                         if atestnumber == #userTShirts then
  173.                                             for i,newbuttons in ipairs(ButtonFolder:GetChildren()) do
  174.                                                 if newbuttons:IsA("TextButton") then
  175.                                                     local newatestnumber = 0
  176.                                                     newatestnumber = newatestnumber + 1
  177.                                                     --print(i,newbuttons)          
  178.                                                     if i == #price then    --tonumber(math.ceil(newbuttons.Text))  --<= tonumber(math.ceil(newbuttons.Text))       
  179.                                                         dictionary = ButtonFolder:GetChildren()
  180.                                                         for _, value in pairs(ButtonFolder:GetChildren()) do
  181.                                                             --dictionary[value.Text] = value.Text;
  182.                                                             --print(unpack(dictionary))
  183.                                                         --  print(value.Text)
  184.                                                         --  print(unpack(dictionary))
  185.                                                         --  print(value)
  186.                                                         --  print(unpack(ButtonFolder:GetChildren()))
  187.                                                             value.Parent = stands:FindFirstChild("PricePart").SurfaceGui.Frame.ScrollingFrame
  188.                                                         end
  189.                                                         -- runs once to clean and reset the values back to their default value!!
  190.                                                         game.ServerStorage:FindFirstChild(Player.Name):Destroy()
  191.                                                         atestnumber = 0
  192.                                                         newatestnumber = 0
  193.                                                     --[[    for i,stands in pairs(Stands:GetDescendants()) do
  194.                                                             if stands:IsA("Model") and stands.Name == "ShopStand" then
  195.                                                                 if stands:FindFirstChild("Owned").Value == true and stands:FindFirstChild("PlayerName").Value == Player.Name then
  196.                                                                     local buttonsinshop = stands.PricePart.SurfaceGui.Frame.ScrollingFrame:GetDescendants()
  197.                                                                 --  print(buttonsinshop[1])
  198.                                                                     for i,v in pairs(buttonsinshop) do
  199.                                                                         if v:IsA("IntValue") and v.Name == "Price" then
  200.                                                                         --  print(v)
  201.                                                                         --  print(v.Value)
  202.                                                                             --table.sort(v)
  203.                                                                             --  print(table.sort(v))
  204.                                                                            
  205.                                                                         --  v = {}
  206.                                                                             --i = i + 1
  207.                                                                     --  table.insert(v, v[i])
  208.                                                                             print(i,v)
  209.                                                                             print(v.Value)
  210.                                                                             local theunpacking,theunpacking2 = table.unpack(buttonsinshop)
  211.                                                                             print(theunpacking2)
  212.                                                                            
  213.                                                                         --  local tableindex = 0
  214.                                                                         --  tableindex = i
  215.                                                                         --  print(tableindex)
  216.                                                                             --tostring(print(i.." - "..v))
  217.                                                                     --      print(v[1])
  218.                                                                     --      print(v[2])
  219.                                                                         end
  220.                                                                     end
  221.                                                                 end
  222.                                                             end
  223.                                                         end --]]
  224.                                                         --print(newbuttons.Text)
  225.                                                         --  newbuttons.Parent = stands:FindFirstChild("PricePart").SurfaceGui.Frame.ScrollingFrame
  226.                                                     end
  227.                                                 end
  228.                                             end
  229.                                         else
  230.                                            
  231.                                     end
  232.                                  end       
  233.                               end  
  234.                            end     
  235.                         end
  236.                     else
  237.         --      print(Player.Name .. " has no tshirts")
  238.             end
  239.                 elseif stands:FindFirstChild("Owned").Value == true and stands:FindFirstChild("PlayerName").Value == Player.Name then
  240.             --      print("Its Your Stand")
  241.                     local Song = "Open Shop"
  242.                     ShopEvent:FireClient(Player,Song)
  243.                 elseif stands:FindFirstChild("Owned").Value == false and stands:FindFirstChild("PlayerName").Value == "" then
  244.                     local Song = "No"
  245.                     ShopEvent:FireClient(Player,Song)
  246.             --      print("you already have a stand")
  247.                 end
  248.             end)
  249.         end
  250.     end
  251.     Player.CharacterAdded:Connect(function(Character)
  252.         task.wait(.5)
  253.     --  print("ProximityPromptUpdater fired")
  254.         ProximityPromptUpdater:FireAllClients(Player)
  255.     end)
  256. end)
  257.  
  258. game.Players.PlayerRemoving:Connect(function(Player)
  259.     for i,stands in pairs(Stands:GetDescendants()) do
  260.         if stands:IsA("Model") and stands.Name == "ShopStand" then
  261.             if stands.Owned.Value == true and stands.PlayerName.Value == Player.Name then
  262.                 stands.TextPart.SurfaceGui:FindFirstChild("TextLabel").Text = "Your Text Here"
  263.                 stands.DescriptionPart.SurfaceGui:FindFirstChild("PlayerName").Text = "unclaimed"
  264.                 stands.DescriptionPart.SurfaceGui:FindFirstChild("PriceRaised").Visible = false
  265.                 stands:FindFirstChild("PricePart").Attachment.ProximityPrompt.Enabled = true
  266.                 stands:FindFirstChild("Owned").Value = false
  267.                 stands:FindFirstChild("PricePart").SurfaceGui.Enabled = false  
  268.                 for i,textbuttons in pairs(Stands:GetDescendants()) do
  269.                     if textbuttons:IsA("TextButton") and textbuttons.Name == "TextButton" then
  270.                         local PlayerName = textbuttons.Parent.Parent.Parent.Parent.Parent.PlayerName.Value
  271.                         if PlayerName == Player.Name then
  272.                             textbuttons:Destroy()
  273.             --              print(textbuttons.Text)
  274.                         else
  275.                 --          print("this shouldnt run i think")
  276.                         end        
  277.                     end
  278.                 end
  279.                 stands:FindFirstChild("PlayerName").Value = ""
  280.                 ProximityPromptUpdater:FireAllClients(Player)          
  281.     --          print("Someone Left")
  282.             end
  283.         end
  284.     end
  285. end)
  286.  
  287. -- Update The Text thats Applied
  288. ShopEvent.OnServerEvent:Connect(function(Player,DescriptionBoardText)
  289.     --print(DescriptionBoardText)
  290.     for i,stands in pairs(Stands:GetDescendants()) do
  291.         if stands:IsA("Model") and stands.Name == "ShopStand" then
  292.             if stands.Owned.Value == true and stands.PlayerName.Value == Player.Name then
  293.                 stands.TextPart.SurfaceGui:FindFirstChild("TextLabel").Text = DescriptionBoardText
  294.             end
  295.         end
  296.     end
  297. end)
  298.  
  299. RefreshEvent.OnServerEvent:Connect(function(Player)
  300. --  print(Player)
  301.     for i,textbuttons in pairs(Stands:GetDescendants()) do
  302.         if textbuttons:IsA("TextButton") and textbuttons.Name == "TextButton" then
  303.             local PlayerName = textbuttons.Parent.Parent.Parent.Parent.Parent.PlayerName.Value
  304.             if PlayerName == Player.Name then
  305.             --  print(textbuttons)
  306.                 textbuttons:Destroy()
  307.             --  wait(1)
  308.             else
  309.  
  310.             end        
  311.         end
  312.     end
  313.    
  314. --  print("start the new button update")
  315.  
  316.     for i,stands in pairs(Stands:GetDescendants()) do
  317.         if stands:IsA("Model") and stands.Name == "ShopStand" then
  318.             if stands.Owned.Value == true and stands.PlayerName.Value == Player.Name then
  319.                 local username =  Player.Name -- "ignaury"
  320.                 local userTShirts = getUserGeneratedTShirtsRecursive(username)
  321.                 wait(.1)
  322.                 local price = getUserGeneratedTShirtsPrices(username)
  323.                 task.wait(.5)
  324.                 local number = #userTShirts or nil
  325.                 if #userTShirts ~= 0 and #userTShirts ~= nil then -- did ~= nil not nessary
  326.                     stands:FindFirstChild("PricePart").SurfaceGui.Enabled = true
  327.                     local TextLocation = game:GetService("ServerStorage")
  328.                     local ButtonFolder = Instance.new("Folder")
  329.                     ButtonFolder.Parent = TextLocation
  330.                     ButtonFolder.Name = Player.Name
  331.                     for i,stands in pairs(Stands:GetDescendants()) do
  332.                         if stands:IsA("Model") and stands.Name == "ShopStand" then
  333.                             if stands:FindFirstChild("Owned").Value == true and stands:FindFirstChild("PlayerName").Value == Player.Name and Player:FindFirstChild("PlayerStandCheck").Value == true then
  334.                                 for i = 1, number do
  335.                                     --      print("Cloning depending on the number")       
  336.                                     local TextClone = TextLocation.ButtonForClone.TextButton:Clone()
  337.                                     TextClone.Parent = ButtonFolder                    
  338.                                     local PriceText = TextClone    
  339.                                     atestnumber = atestnumber + 1
  340.                                     PriceText.Text = price[atestnumber] .. "$"
  341.                                     PriceText.Price.Value = price[atestnumber]
  342.                                     PriceText:FindFirstChild("id").Value = userTShirts[atestnumber]
  343.                                     if atestnumber == #userTShirts then
  344.                                         for i,newbuttons in ipairs(ButtonFolder:GetChildren()) do
  345.                                             if newbuttons:IsA("TextButton") then
  346.                                                 local newatestnumber = 0
  347.                                                 newatestnumber = newatestnumber + 1
  348.                                                 if i == #price then    
  349.                                                     dictionary = ButtonFolder:GetChildren()
  350.                                                     for _, value in pairs(ButtonFolder:GetChildren()) do
  351.                                                         value.Parent = stands:FindFirstChild("PricePart").SurfaceGui.Frame.ScrollingFrame
  352.                                                     end
  353.                                                     -- runs once to clean and reset the values back to their default value!!
  354.                                                     game.ServerStorage:FindFirstChild(Player.Name):Destroy()
  355.                                                     atestnumber = 0
  356.                                                     newatestnumber = 0
  357.                                                     wait(.1)
  358.                                             --      ProximityPromptUpdater:FireClient(Player)
  359.                                                 end
  360.                                             end
  361.                                         end
  362.                                     else
  363.  
  364.                                     end
  365.                                 end    
  366.                             end
  367.                         end    
  368.                     end
  369.                 else
  370.  
  371.                 end
  372.             end
  373.         end
  374.     end
  375. end)
  376.  
  377. UnclaimEvent.OnServerEvent:Connect(function(Player)
  378.     for i,stands in pairs(Stands:GetDescendants()) do
  379.         if stands:IsA("Model") and stands.Name == "ShopStand" then
  380.             if stands.Owned.Value == true and stands.PlayerName.Value == Player.Name then
  381.                 stands.TextPart.SurfaceGui:FindFirstChild("TextLabel").Text = "Your Text Here"
  382.                 stands.DescriptionPart.SurfaceGui:FindFirstChild("PlayerName").Text = "unclaimed"
  383.                 stands.DescriptionPart.SurfaceGui:FindFirstChild("PriceRaised").Visible = false
  384.                 stands:FindFirstChild("PricePart").Attachment.ProximityPrompt.Enabled = true
  385.                 stands:FindFirstChild("Owned").Value = false
  386.                 stands:FindFirstChild("PricePart").SurfaceGui.Enabled = false  
  387.                 for i,textbuttons in pairs(Stands:GetDescendants()) do
  388.                     if textbuttons:IsA("TextButton") and textbuttons.Name == "TextButton" then
  389.                         local PlayerName = textbuttons.Parent.Parent.Parent.Parent.Parent.PlayerName.Value
  390.                         if PlayerName == Player.Name then
  391.                             textbuttons:Destroy()                      
  392.                         else
  393.  
  394.                         end        
  395.                     end
  396.                 end
  397.                 stands:FindFirstChild("PlayerName").Value = ""
  398.                 Player:FindFirstChild("PlayerStandCheck").Value = false
  399.                 UnclaimEvent:FireClient(Player)
  400.                 ProximityPromptUpdater:FireAllClients(Player)      
  401.             end
  402.         end
  403.     end
  404. end)
  405.  
  406. StandColorChangeEvent.OnServerEvent:Connect(function(Player,ButtonPrice)
  407.     print(ButtonPrice)
  408.    
  409.     for i,stands in pairs(Stands:GetDescendants()) do
  410.         if stands:IsA("Model") and stands.Name == "ShopStand" then
  411.             if stands.Owned.Value == true and stands.PlayerName.Value == Player.Name then
  412.                 if ButtonPrice == 0 and Player.leaderstats["Raised 💰"].Value >= 0 then
  413.                     print("starter button pressed")
  414.                 elseif ButtonPrice == 1000 and Player.leaderstats["Raised 💰"].Value >= 1000 then
  415.                     print("button 1k pressed")
  416.                 elseif ButtonPrice == 10000 and Player.leaderstats["Raised 💰"].Value >= 10000 then
  417.                     print("button 10k pressed")
  418.                 elseif ButtonPrice == 100000 and Player.leaderstats["Raised 💰"].Value >= 100000 then
  419.                     print("button 100k pressed")
  420.                 elseif ButtonPrice == 1000000 and Player.leaderstats["Raised 💰"].Value >= 1000000 then
  421.                     print("button 1000k or 1 milion pressed")  
  422.                 end
  423.             end
  424.         end
  425.     end
  426. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement