Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.86 KB | None | 0 0
  1. -- Gui loader
  2. -- Yikes, this scirpt is I think one of the longest I've ever writen.
  3. local player = game.Players.LocalPlayer
  4. local ReplicatedStorage = game:GetService('ReplicatedStorage')
  5. local products = require(ReplicatedStorage:WaitForChild('Products'))
  6. local itemsArray = require(ReplicatedStorage:WaitForChild('Items'))
  7. local DevProducts = products['DevProducts']
  8. local GamePasses = products['GamePasses']
  9. local UpdateTotalProfit = ReplicatedStorage.GUI:WaitForChild('UpdateTotalProfit')
  10. local MessagePrefix = 'This game has made '
  11. local UI = player.PlayerGui:WaitForChild('UI')
  12. local DevProdFrame = UI.Shop.Coins.Items
  13. local GamePassFrame = UI.Shop.Passes.Items
  14. local ShopOpened = UI.Shop.Opened
  15. local UpgradeOpened = UI.Items.Opened
  16. local TweeningShop = false
  17. local TweeningUpgrade = false
  18. local BuyRemote = ReplicatedStorage.GUI:WaitForChild('BuyItem')
  19. local MarketplaceService = game:GetService("MarketplaceService")
  20. local PlayerWaitEvent = ReplicatedStorage.GUI:WaitForChild('PlayerWait')
  21. local AnnounceEvent = ReplicatedStorage.GUI:WaitForChild('Announce')
  22. local TimerEvent = ReplicatedStorage.GUI:WaitForChild('Timer')
  23.  
  24. -- ANNOUNCE HANDLER --
  25.  
  26. local function announce(title, message)
  27.     warn('Recieved Announcement, '..title..' & '..message)
  28.     local AnnouncementFrame = UI.Announcement
  29.     AnnouncementFrame.Title.Text = title
  30.     AnnouncementFrame.Message.Text = message
  31.     AnnouncementFrame.Visible = true
  32.     AnnouncementFrame.Position = UDim2.new(0, -300,0.5, -75)
  33.     AnnouncementFrame:TweenPosition(UDim2.new(0.5, -150,0.5, -75), 'Out', 'Bounce', 1)
  34.     wait(3)
  35.     AnnouncementFrame:TweenPosition(UDim2.new(1, 0,0.5, -75), 'In', 'Bounce', 1)
  36.     wait(1)
  37.     AnnouncementFrame.Visible = false
  38. end
  39.  
  40. AnnounceEvent.OnClientEvent:Connect(announce)
  41.  
  42. -- TIMER HANDLER --
  43.  
  44. local function timer(seconds)
  45.     warn('Starting Timer on Chient for '..tostring(seconds)..' seconds')
  46.     local TimerFrame = UI.timer
  47.     TimerFrame.Position = UDim2.new(0.5, -100,0, -110)
  48.     TimerFrame.Visible = true
  49.     TimerFrame:TweenPosition(UDim2.new(0.5, -100, 0, 0), 'Out', 'Bounce', 1)
  50.     TimerFrame.Timer.Text = 'LOADING'
  51.     TimerFrame.Timer.Shadow.Text = 'LOADING'   
  52.     wait(1)
  53.     for i=seconds, 0, -1 do
  54.         TimerFrame.Timer.Text = i
  55.         TimerFrame.Timer.Shadow.Text = i
  56.         wait(1)
  57.     end
  58.     TimerFrame.Timer.Text = 'DONE'
  59.     TimerFrame.Timer.Shadow.Text = 'DONE'
  60.     TimerFrame:TweenPosition(UDim2.new(0.5, -100, 0, -110), 'Out', 'Bounce', 1)
  61.     wait(1)
  62.     TimerFrame.Visible = false
  63. end
  64.  
  65. TimerEvent.OnClientEvent:Connect(timer)
  66.  
  67. -------------------------------------------------
  68.  
  69. function addComas(str)
  70.     str = tostring(str)
  71.     return #str % 3 == 0 and str:reverse():gsub("(%d%d%d)", "%1,"):reverse():sub(2) or str:reverse():gsub("(%d%d%d)", "%1,"):reverse()
  72. end
  73.  
  74. function round(num, numDecimalPlaces)
  75.   return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
  76. end
  77.  
  78. local function UpdateClient(amount)
  79.     local Shop = UI.Shop
  80.     Shop.Profit.Text = MessagePrefix..addComas(round(amount, 0))..'R$'
  81. end
  82.  
  83. -- GUI LOADERS --
  84.  
  85. local function setPlayerInformation()
  86.     local PlayerInfo = UI.PlayerInformation
  87.     PlayerInfo.NameLabel.Text = player.Name
  88.     PlayerInfo.NameLabel.Shadow.Text = player.Name
  89.     PlayerInfo.PlayerIcon.Image = game.Players:GetUserThumbnailAsync(player.UserId, "HeadShot", "Size352x352")
  90. end
  91.  
  92. local function LoadItems()
  93.     local Items = UI.Items
  94.     local ItemNumber1, ItemNumber2, ItemNumber3 = Items.Item1, Items.Item2, Items.Item3
  95.     -- ITEM #1 --
  96.     ItemNumber1.Icon.Image = itemsArray['Item1']['Icon']
  97.     ItemNumber1.Title.Text = itemsArray['Item1']['Name']
  98.     ItemNumber1.Title.Shadow.Text = itemsArray['Item1']['Name']
  99.     ItemNumber1.Cost.Text = itemsArray['Item1']['Price']
  100.     ItemNumber1.Cost.Shadow.Text = itemsArray['Item1']['Price']
  101.     ItemNumber1.String.Value = itemsArray['Item1']['String']
  102.     -- ITEM #2 --
  103.     ItemNumber2.Icon.Image = itemsArray['Item2']['Icon']
  104.     ItemNumber2.Title.Text = itemsArray['Item2']['Name']
  105.     ItemNumber2.Title.Shadow.Text = itemsArray['Item2']['Name']
  106.     ItemNumber2.Cost.Text = itemsArray['Item2']['Price']
  107.     ItemNumber2.Cost.Shadow.Text = itemsArray['Item2']['Price']
  108.     ItemNumber2.String.Value = itemsArray['Item2']['String']
  109.     -- ITEM #3 --
  110.     ItemNumber3.Icon.Image = itemsArray['Item3']['Icon']
  111.     ItemNumber3.Title.Text = itemsArray['Item3']['Name']
  112.     ItemNumber3.Title.Shadow.Text = itemsArray['Item3']['Name']
  113.     ItemNumber3.Cost.Text = itemsArray['Item3']['Price']
  114.     ItemNumber3.Cost.Shadow.Text = itemsArray['Item3']['Price']
  115.     ItemNumber3.String.Value = itemsArray['Item3']['String']
  116. end
  117.  
  118. local function LoadShop()
  119.     local Shop = UI.Shop
  120.     local Coins = Shop.Coins
  121.     local Passes = Shop.Passes
  122.     local DevProduct1, DevProduct2, DevProduct3 = Coins.Items.DevProduct1, Coins.Items.DevProduct2, Coins.Items.DevProduct3
  123.     local GamePass1, GamePass2, GamePass3 = Passes.Items.GamePass1, Passes.Items.GamePass2, Passes.Items.GamePass3
  124.     -- DEV PRODUCT #1 --
  125.     DevProduct1.Title.Text = DevProducts['DevProduct1']['Name']
  126.     DevProduct1.Title.Shadow.Text = DevProducts['DevProduct1']['Name']
  127.     DevProduct1.Costs.Text = DevProducts['DevProduct1']['Price']
  128.     DevProduct1.Costs.Shadow.Text = DevProducts['DevProduct1']['Price']
  129.     DevProduct1.Icon.Image = DevProducts['DevProduct1']['Icon']
  130.     DevProduct1.Id.Value = DevProducts['DevProduct1']['ID']
  131.     -- DEV PRODUCT #2 --
  132.     DevProduct2.Title.Text = DevProducts['DevProduct2']['Name']
  133.     DevProduct2.Title.Shadow.Text = DevProducts['DevProduct2']['Name']
  134.     DevProduct2.Costs.Text = DevProducts['DevProduct2']['Price']
  135.     DevProduct2.Costs.Shadow.Text = DevProducts['DevProduct2']['Price']
  136.     DevProduct2.Icon.Image = DevProducts['DevProduct2']['Icon']
  137.     DevProduct2.Id.Value = DevProducts['DevProduct2']['ID']
  138.     -- DEV PRODUCT #3 --
  139.     DevProduct3.Title.Text = DevProducts['DevProduct3']['Name']
  140.     DevProduct3.Title.Shadow.Text = DevProducts['DevProduct3']['Name']
  141.     DevProduct3.Costs.Text = DevProducts['DevProduct3']['Price']
  142.     DevProduct3.Costs.Shadow.Text = DevProducts['DevProduct3']['Price']
  143.     DevProduct3.Icon.Image = DevProducts['DevProduct3']['Icon']
  144.     DevProduct3.Id.Value = DevProducts['DevProduct3']['ID']
  145.     -- GAME PASS #1 --
  146.     GamePass1.Title.Text = GamePasses['GamePass1']['Name']
  147.     GamePass1.Title.Shadow.Text = GamePasses['GamePass1']['Name']
  148.     GamePass1.Costs.Text = GamePasses['GamePass1']['Price']
  149.     GamePass1.Costs.Shadow.Text = GamePasses['GamePass1']['Price']
  150.     GamePass1.Icon.Image = GamePasses['GamePass1']['Icon']
  151.     GamePass1.Id.Value = GamePasses['GamePass1']['ID']
  152.     -- GAME PASS #2 --
  153.     GamePass2.Title.Text = GamePasses['GamePass2']['Name']
  154.     GamePass2.Title.Shadow.Text = GamePasses['GamePass2']['Name']
  155.     GamePass2.Costs.Text = GamePasses['GamePass2']['Price']
  156.     GamePass2.Costs.Shadow.Text = GamePasses['GamePass2']['Price']
  157.     GamePass2.Icon.Image = GamePasses['GamePass2']['Icon']
  158.     GamePass2.Id.Value = GamePasses['GamePass2']['ID']
  159.     -- GAME PASS #3 --
  160.     GamePass3.Title.Text = GamePasses['GamePass3']['Name']
  161.     GamePass3.Title.Shadow.Text = GamePasses['GamePass3']['Name']
  162.     GamePass3.Costs.Text = GamePasses['GamePass3']['Price']
  163.     GamePass3.Costs.Shadow.Text = GamePasses['GamePass3']['Price']
  164.     GamePass3.Icon.Image = GamePasses['GamePass3']['Icon']
  165.     GamePass3.Id.Value = GamePasses['GamePass3']['ID']
  166. end
  167.  
  168. local function UpdateValues()
  169.     local leaderstats = player:WaitForChild('leaderstats')
  170.     local wins = leaderstats.Wins
  171.     local coins = leaderstats.Coins
  172.     local PlayerInformation = UI.PlayerInformation
  173.     spawn(function()
  174.         while wait(0.5) do
  175.             PlayerInformation.WinCounter.Text = ("TOTAL WINS: ".. wins.Value)
  176.             PlayerInformation.CoinCounter.Text = ('COINS: '.. coins.Value)
  177.             UI.Items.CoinStatus.Text = 'You currently have '.. coins.Value ..' coins'
  178.             UI.Items.CoinStatus.Shadow.Text = 'You currently have '.. coins.Value ..' coins'
  179.         end
  180.     end)
  181. end
  182.  
  183. local function shop(bool)
  184.     if bool == true then --Open Shop
  185.         UI.Shop.Visible = true
  186.         UI.Shop.Position = UDim2.new(0.5, -353,1, 0)
  187.         UI.Shop:TweenPosition(UDim2.new(0.5, -353,0.5, -250), 'Out', 'Bounce', 1, true)
  188.     end
  189.     if bool == false then -- Close Shop
  190.         UI.Shop:TweenPosition(UDim2.new(0.5, -353,0, -490), 'Out', 'Bounce', 1, true)
  191.         wait(1)
  192.         UI.Shop.Visible = false
  193.     end
  194. end
  195.  
  196. local function items(bool)
  197.     if bool == true then
  198.         ShopOpened.Value = true
  199.         UI.Items.Visible = true
  200.         UI.Items.Position = UDim2.new(0.5, -350,1, 0)
  201.         UI.Items:TweenPosition(UDim2.new(0.5, -350,0.5, -100), 'Out', 'Bounce', 1, true)
  202.     end
  203.     if bool == false then
  204.         ShopOpened.Value = false
  205.         UI.Items.Position = UDim2.new(0.5, -350,0.5, -100)
  206.         UI.Items:TweenPosition(UDim2.new(0.5, -350,0, -250), 'Out', 'Bounce', 1, true)
  207.         wait(1)
  208.         UI.Items.Visible = false
  209.     end
  210. end
  211.  
  212. local function ClientBuy(item)
  213.     local info = (BuyRemote:InvokeServer(item))
  214.     local alert = UI.Alert:Clone()
  215.     alert.Parent = UI
  216.     alert.Visible = true
  217.     alert.Position = UDim2.new(0.5, -150, 1, 0)
  218.     alert.Title.Text = info[1]
  219.     alert.Message.Text = info[2]
  220.     alert:TweenPosition(UDim2.new(0.5, -150, 0.5, -75), 'Out', 'Bounce', 1)
  221. end
  222.  
  223. UI.Items.GetMore.MouseButton1Click:connect(function()
  224.     items(false)
  225.     shop(true)
  226. end)
  227.  
  228. UI.Shop.Close.MouseButton1Click:connect(function()
  229.     shop(false)
  230. end)
  231.  
  232. UI.UpgradeButton.MouseButton1Click:connect(function()
  233.     if Items
  234.     shop(true)
  235. end)
  236.  
  237. UI.ShopButton.MouseButton1Click:connect(function()
  238.     if ShopOpened.Value == false then
  239.         items(true)
  240.     else
  241.         items(false)
  242.     end
  243. end)
  244.  
  245. UI.Items.Close.MouseButton1Click:connect(function()
  246.     items(false)
  247. end)
  248.  
  249. UI.Items.Item1.Buy.MouseButton1Click:connect(function()
  250.     ClientBuy(UI.Items.Item1.String.Value)
  251. end)
  252.  
  253. UI.Items.Item2.Buy.MouseButton1Click:connect(function()
  254.     ClientBuy(UI.Items.Item2.String.Value)
  255. end)
  256.  
  257. UI.Items.Item3.Buy.MouseButton1Click:connect(function()
  258.     ClientBuy(UI.Items.Item3.String.Value)
  259. end)
  260.  
  261. DevProdFrame.DevProduct1.TextButton.MouseButton1Click:connect(function()
  262.     local id = DevProdFrame.DevProduct1.Id.Value
  263.     MarketplaceService:PromptProductPurchase(player, id)
  264. end)
  265.  
  266. DevProdFrame.DevProduct2.TextButton.MouseButton1Click:connect(function()
  267.     local id = DevProdFrame.DevProduct2.Id.Value
  268.     MarketplaceService:PromptProductPurchase(player, id)
  269. end)
  270.  
  271. DevProdFrame.DevProduct3.TextButton.MouseButton1Click:connect(function()
  272.     local id = DevProdFrame.DevProduct3.Id.Value
  273.     MarketplaceService:PromptProductPurchase(player, id)
  274. end)
  275.  
  276. GamePassFrame.GamePass1.TextButton.MouseButton1Click:connect(function()
  277.     local id = GamePassFrame.GamePass1.Id.Value
  278.     MarketplaceService:PromptGamePassPurchase(player, id)
  279. end)
  280.  
  281. GamePassFrame.GamePass2.TextButton.MouseButton1Click:connect(function()
  282.     local id = GamePassFrame.GamePass2.Id.Value
  283.     MarketplaceService:PromptGamePassPurchase(player, id)
  284. end)
  285.  
  286. GamePassFrame.GamePass3.TextButton.MouseButton1Click:connect(function()
  287.     local id = GamePassFrame.GamePass3.Id.Value
  288.     MarketplaceService:PromptGamePassPurchase(player, id)
  289. end)
  290.  
  291. local function load()
  292.     UI.Enabled = true
  293.     UpdateValues()
  294.     setPlayerInformation()
  295.     LoadShop()
  296.     LoadItems()
  297.     UpdateTotalProfit.OnClientEvent:Connect(UpdateClient)
  298. end
  299.  
  300. load()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement