Advertisement
qsenko1

TrailShopClientButton

Apr 25th, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. -- Variables
  2. local replicatedStorage = game.ReplicatedStorage
  3. local shopFrameButton = script.Parent
  4. local trailsData = replicatedStorage.Trails
  5. local Mariotrail = game.ReplicatedStorage.Trails:FindFirstChild("Mario")
  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(Mariotrail.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 == Mariotrail.Name then
  19.             shopFrameButton.TrailPrice.Text = "Equipped"       
  20.             --print(trail.Name)
  21.         end
  22.  
  23.         shopFrameButton.MouseButton1Click:Connect(function()
  24.             local result = replicatedStorage.Events.BuyItem35:InvokeServer(Mariotrail.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)
  46.  
  47. while wait(0.5)do
  48.     -- Update your inventory
  49.     if game.Players.LocalPlayer.TrailInventory:FindFirstChild(Mariotrail.Name) then
  50.         shopFrameButton.TrailPrice.Text = "Owned"
  51.     end
  52.     -- Update your equipped Trail
  53.     if game.Players.LocalPlayer.EquippedTrail.Value == Mariotrail.Name then
  54.         shopFrameButton.TrailPrice.Text = "Equipped"       
  55.     end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement