qsenko1

TrailButton

Apr 24th, 2021 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. -- Variables
  2. local replicatedStorage = game.ReplicatedStorage
  3. local shopFrameButton = script.Parent
  4. local trailsData = replicatedStorage.Trails
  5. local Redtrail = game.ReplicatedStorage.Trails:FindFirstChild("Red")
  6. -- Function to setup the trail
  7.  
  8. function trailsSetup(dataFolder)
  9.     for index, trail in pairs(dataFolder:GetChildren()) do
  10.         --local trailFrame = shopFrameButton.Parent(trail.Name,trail.Price.Value,trail.Color)
  11.  
  12.         -- Update your inventory
  13.         if game.Players.LocalPlayer.TrailInventory:FindFirstChild(Redtrail.Name) then
  14.             shopFrameButton.TrailPrice.Text = "Owned"
  15.             print(trail.Name)
  16.         end
  17.         -- Update your equipped Trail
  18.         if game.Players.LocalPlayer.EquippedTrail.Value == Redtrail.Name then
  19.             shopFrameButton.TrailPrice.Text = "Equipped"       
  20.             print(trail.Name)
  21.         end
  22.  
  23.         shopFrameButton.MouseButton1Click:Connect(function()
  24.             local result = replicatedStorage.Events.BuyItem2:InvokeServer(Redtrail.Name)
  25.  
  26.             if result == "Brought" then
  27.                 shopFrameButton.TrailPrice.Text = "Owned"
  28.             elseif result == "NotEnough" then
  29.                 shopFrameButton.TrailPrice.Text = "Not Enough Coins"
  30.                 wait(.5)
  31.                 shopFrameButton.TrailPrice.Text = "100 Coins"
  32.             elseif result == "Equip" then          
  33.                 shopFrameButton.TrailPrice.Text = "Equipped"
  34.             elseif result == "Unequip" then
  35.                 shopFrameButton.TrailPrice.Text = "Owned"
  36.             end
  37.         end)
  38.     end
  39. end
  40.  
  41. -- If data is loaded up, it will bring your items
  42.  
  43. replicatedStorage.Events.SendData.OnClientEvent:Connect(function()
  44.     trailsSetup(trailsData)
  45. end)
Add Comment
Please, Sign In to add comment