Advertisement
HowToRoblox

AdvertisementsClient

Jul 29th, 2022
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. --HIDE GUI ON START
  2. local adFrame = script.Parent:WaitForChild("AdFrame")
  3. adFrame.Visible = false
  4.  
  5. --VARIABLES
  6. local createBtn = script.Parent:WaitForChild("CreateAdButton")
  7. local closeBtn = adFrame:WaitForChild("CloseButton")
  8. local nameLbl = adFrame:WaitForChild("ItemName")
  9. local thumbnailImg = adFrame:WaitForChild("ItemThumbnail")
  10. local confirmBtn = adFrame:WaitForChild("ConfirmButton")
  11. local idBox = adFrame:WaitForChild("ItemIDBox")
  12.  
  13.  
  14. --OPEN AND CLOSE GUI WHEN BUTTONS ARE PRESSED
  15. createBtn.MouseButton1Click:Connect(function()
  16.     adFrame.Visible = true
  17.    
  18.     nameLbl.Text = "Item name"
  19.     thumbnailImg.Image = "http://www.roblox.com/asset/?id=9586437451"
  20.     idBox.Text = ""
  21. end)
  22.  
  23. closeBtn.MouseButton1Click:Connect(function()
  24.     adFrame.Visible = false
  25. end)
  26.  
  27.  
  28. --CREATE AD PREVIEW WHEN ID IS ENTERED
  29. local marketplaceService = game:GetService("MarketplaceService")
  30.  
  31. idBox.FocusLost:Connect(function(enterPressed)
  32.    
  33.     local enteredId = idBox.Text
  34.    
  35.     if string.len(enteredId) > 0 and enterPressed then
  36.         local productInfo = marketplaceService:GetProductInfo(enteredId)
  37.        
  38.         if productInfo then
  39.            
  40.             local name = productInfo.Name
  41.             nameLbl.Text = name
  42.  
  43.             thumbnailImg.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=" .. enteredId .. "&width=420&height=420&format=png"
  44.         end
  45.     end
  46. end)
  47.  
  48.  
  49. --SEND MESSAGE TO SERVER TO CREATE AD WHEN CONFIRM BUTTON IS PRESSED
  50. local remoteEvent = game.ReplicatedStorage:WaitForChild("AdvertisementsRE")
  51.  
  52. confirmBtn.MouseButton1Click:Connect(function()
  53.    
  54.     remoteEvent:FireServer(tonumber(idBox.Text))
  55.    
  56.     adFrame.Visible = false
  57. end)
  58.  
  59.  
  60. --PROMPT PLAYER TO BUY PRODUCT OR JOIN PLACE WHEN THEY CLICK ON THE ITEM BUTTON
  61. local teleportService = game:GetService("TeleportService")
  62.  
  63. remoteEvent.OnClientEvent:Connect(function(button)
  64.    
  65.     if button:FindFirstChild("ID") then
  66.        
  67.         local id = button.ID.Value
  68.        
  69.         local productInfo = marketplaceService:GetProductInfo(id)
  70.        
  71.         local typeId = productInfo.AssetTypeId
  72.        
  73.         if typeId == 9 then
  74.             teleportService:Teleport(id, game.Players.LocalPlayer)
  75.            
  76.         else
  77.             marketplaceService:PromptPurchase(game.Players.LocalPlayer, id)
  78.         end
  79.     end
  80. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement