qsenko1

Synched Trail Shop Gamepass

Jul 10th, 2021 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.92 KB | None | 0 0
  1. -- Server Side
  2. local trails = script.Parent:GetDescendants()
  3. local debounce = true
  4. local debounce2 = true
  5. --print(trails)
  6.  
  7. game.Players.PlayerAdded:Connect(function(player)
  8. wait(1)
  9. local VisualScript = script.LocalScript:Clone()
  10. VisualScript.Parent = player.PlayerGui
  11. VisualScript.Disabled = false
  12. player.CharacterAdded:Connect(function(Character)
  13.         wait(1)
  14. local VisualScript = script.LocalScript:Clone()
  15. VisualScript.Parent = player.PlayerGui
  16. VisualScript.Disabled = false      
  17. end)
  18. for i, v in pairs(trails)do
  19. if v:IsA("Trail") and v.Name == "Trail" then           
  20. if player then
  21. --print(player.Name)    -- it finds the player             
  22. wait(0.5)              
  23. --print(player.EquippedTrail.Value) -- its nil?
  24. --print(v.Parent.Name == player.EquippedTrail.Value) -- its false
  25. if v.Parent.Name == player.EquippedTrail.Value and debounce2 then
  26.     debounce2 = false
  27.     --print("Trail Loaded!!")  
  28.     local attachment1 = Instance.new("Attachment",player.Character:FindFirstChild("HumanoidRootPart"))
  29.     local attachment2 = Instance.new("Attachment",player.Character:FindFirstChild("Head"))                             
  30.     local trail = v:Clone()
  31.     trail.Parent = player.Character
  32.     trail.Attachment0 = attachment1
  33.     trail.Attachment1 = attachment2
  34.     wait(1)
  35.         debounce2 = true
  36.     end
  37. end
  38. player.CharacterAdded:Connect(function(Character)      
  39. if v.Parent.Name == player.EquippedTrail.Value then
  40.             --  print("trail will copy")
  41.                 local attachment1 = Instance.new("Attachment",Character:FindFirstChild("HumanoidRootPart"))
  42.                 local attachment2 = Instance.new("Attachment",Character:FindFirstChild("Head"))                            
  43.                 local trail = v:Clone()
  44.                 trail.Parent = Character
  45.                 trail.Attachment0 = attachment1
  46.                 trail.Attachment1 = attachment2    
  47.              end
  48.           end)
  49.        end
  50.     end
  51. end)
  52.  
  53. -- these 2 nested for loops get all of the Trails,names and prices when you first join
  54.  
  55. for i, name in pairs(trails)do
  56.     if name:IsA("TextLabel") and name.Name == "Name" then
  57.         name.Text = name.Parent.Parent.Parent.Name
  58.         for i, prices in pairs(trails)do
  59.             if prices:IsA("TextLabel") and prices.Name == "Price" then
  60.                 prices.Text = prices.Parent.Parent.Parent:FindFirstChild("Price").Value.. " Robux"
  61.             end
  62.         end
  63.     end
  64. end
  65.  
  66. for i,v in pairs(trails)do
  67.     --print(trails) -- gets a table of all objects
  68.     --print(v)-- prints all objects
  69.     if v:IsA("Part") and v.Name == "TouchPad" then
  70.         for i, p in pairs(trails)do
  71.             v.Touched:Connect(function(hit)
  72.             local player = game.Players:GetPlayerFromCharacter(hit.Parent)         
  73.             local character = player.Character     
  74.             if p:IsA("Model") and v.Parent and debounce then
  75.             debounce = false   
  76.             --print(v.Parent)
  77.             --print(player)
  78.             --print(p.Value)
  79.                 local id = v.Parent:FindFirstChild("GamepassId").Value
  80.                 local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) 
  81.                 --  local ProductInfo = game:GetService("MarketplaceService"):GetProductInfo(id, Enum.InfoType.Product)
  82.                 --  local Price = ProductInfo.PriceInRobux     
  83.                     local success, errormessage = pcall(ownsGamepass);
  84.                 --  print(id) -- returns the id of the pass!!
  85.                     --  print(ProductInfo)
  86.             --      print(ownsGamepass) -- it returns true!!
  87.                     -- the whatever below is a simple experiment
  88.                     --[[local function TrailNamePrice()
  89.                             for i, prices in pairs(trails)do
  90.                                 if prices:IsA("TextLabel") and prices.Name == "Price" then
  91.                                    if character:FindFirstChild("Trail")  and ownsGamepass then
  92.                                         v.Parent:FindFirstChild("GroupTag"):FindFirstChild("Frame"):FindFirstChild("Price").Text = "Equipped"          
  93.                                         print(prices.Parent "1")
  94.                                     end
  95.                                    
  96.                                     if not character:FindFirstChild("Trail") and ownsGamepass then
  97.                                         v.Parent:FindFirstChild("GroupTag"):FindFirstChild("Frame"):FindFirstChild("Price").Text = "Owned" 
  98.                                         print(prices.Parent "2")
  99.                                     end
  100.                                    
  101.                                     if not character:FindFirstChild("Trail") and not ownsGamepass then                     
  102.                                         prices.Text = prices.Parent.Parent.Parent:FindFirstChild("Price").Value.. " Robux"
  103.                                         print(prices.Parent "3")
  104.                                 end
  105.                             end
  106.                         end
  107.                     end
  108.                     TrailNamePrice()                   
  109.                 end--]]
  110.                     if player and game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) ~= true then           
  111.                         local id2 = v.Parent:FindFirstChild("GamepassId").Value
  112.                         print(game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id))
  113.                 --      print("I dont own the gamepass ".. id2)
  114.                         game:GetService("MarketplaceService"):PromptGamePassPurchase(player,id)
  115.                     --  v.Parent:FindFirstChild("GroupTag"):FindFirstChild("Frame"):FindFirstChild("Price").Text = v.Parent.Price.Value " Robux"
  116.                     end
  117.                    
  118.                     if ownsGamepass and player then        
  119.                         for i, t in pairs(character:GetChildren())do
  120.                         if character.HumanoidRootPart:FindFirstChild("Attachment") then character.HumanoidRootPart.Attachment:Destroy() end
  121.                         if character.Head:FindFirstChild("Attachment") then character.Head.Attachment:Destroy() end
  122.                         if character.Torso:FindFirstChild("Attachment") then character.Torso.Attachment:Destroy() end
  123.                         if character:FindFirstChild(player.Name.."'s Trail") then character[player.Name.."'s Trail"]:Destroy() end
  124.                         if t:IsA("Trail") and t.Name == "Trail" and character:FindFirstChild("Trail") then
  125.                                 character:FindFirstChild("Trail"):Destroy()  
  126.                                 player:FindFirstChild("EquippedTrail").Value = ""
  127.                             --  print("Destroying")
  128.                             --  v.Parent:FindFirstChild("GroupTag"):FindFirstChild("Frame"):FindFirstChild("Price").Text = "Owned"
  129.                             break  
  130.                         end
  131.                            
  132.                         if not character:FindFirstChild("Trail") then
  133.                         local attachment1 = Instance.new("Attachment",character:FindFirstChild("HumanoidRootPart"))
  134.                         local attachment2 = Instance.new("Attachment",character:FindFirstChild("Head"))                            
  135.                         local trail = v.Parent:FindFirstChild("Trail"):Clone()
  136.                         trail.Parent = character
  137.                         trail.Attachment0 = attachment1
  138.                         trail.Attachment1 = attachment2
  139.                         player:FindFirstChild("EquippedTrail").Value = v.Parent.Name
  140.                     --  print("Cloning")                           
  141.                     --  v.Parent:FindFirstChild("GroupTag"):FindFirstChild("Frame"):FindFirstChild("Price").Text = "Equipped"      
  142.                               break
  143.                            end 
  144.                         end
  145.                      end
  146.                  wait(1)
  147.                 debounce = true    
  148.               end  
  149.           end)
  150.        end
  151.     end
  152. end
  153.  
  154. -- Client Side!!!
  155.  
  156. local player = game.Players.LocalPlayer
  157. local debounce = true
  158. local trails = game.Workspace.Trails:GetDescendants()
  159.  
  160. for i, v in pairs(trails)do
  161.     if v:IsA("Part") and v.Name == "TouchPad" then
  162.         v.Touched:Connect(function(hit)
  163.             if player and debounce then
  164.                 debounce = false               
  165.                 local id = v.Parent.GamepassId.Value
  166.                 local price = v.Parent.Price
  167.                 local Text = v.Parent.GroupTag.Frame.Price
  168.                 local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id)
  169.                 local Character = player.Character
  170.                 --print(v.Parent.Name)     
  171.             if ownsGamepass then
  172.                     if not Character:FindFirstChild("Trail") then  
  173.                         Text.Text = "Equipped" 
  174.                     end    
  175.                     if Character:FindFirstChild("Trail") then  
  176.                         Text.Text = "Owned"
  177.                     end
  178.             end
  179.                 wait(1)
  180.                 debounce = true    
  181.             end
  182.         end)
  183.     end
  184. end
  185. local debounce2 = true
  186. while wait() do
  187.     for i, v in pairs(trails)do
  188.         if v:IsA("Part") and v.Name == "TouchPad" then
  189.             local id = v.Parent.GamepassId.Value
  190.             local price = v.Parent.Price
  191.             local Text = v.Parent.GroupTag.Frame.Price
  192.             local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id)
  193.             local Character = player.Character
  194.            
  195.             if ownsGamepass and v.Parent.Name == player.EquippedTrail.Value and debounce2 then     
  196.                 debounce = false
  197.                 Text.Text = "Equipped"
  198.                 --  break
  199.                 wait(0.1)
  200.                 debounce = true
  201.             end
  202.            
  203.             if ownsGamepass and v.Parent.Name ~= player.EquippedTrail.Value and debounce2 then
  204.                 debounce = false
  205.                 Text.Text = "Owned"
  206.                 wait(0.1)
  207.                 debounce = true
  208.             end    
  209.         end
  210.     end
  211. end
Add Comment
Please, Sign In to add comment