Er1x_Official

main script, shop tutorial

Aug 29th, 2021
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. local item_folder = game.ReplicatedStorage.items -- get the folder
  2. local item1price = 50 -- item price
  3. local item2price = 50 -- item price
  4.  
  5. game.Players.PlayerAdded:Connect(function(player) -- leader board set up
  6.     local folder = Instance.new("Folder",player)
  7.     folder.Name = "leaderstats"
  8.    
  9.     local coins = Instance.new("IntValue",folder)
  10.     coins.Name = "Coins"
  11.     coins.Value = 100
  12. end)
  13.  
  14. game.ReplicatedStorage.buy.OnServerEvent:Connect(function(player, item) -- buy
  15.     if item == "Sword" then -- item name
  16.         local coins = tonumber(player.leaderstats.Coins.Value) -- get the coins
  17.        
  18.         if coins >= item1price then -- check if the player has enough money to buy the coins
  19.             coins = coins - item1price -- minus the coins to the price
  20.             local i = item_folder.ClassicSword:Clone() -- get & clone the sword
  21.             i.Parent = player.Backpack -- place the sword to the players inventory
  22.             player.leaderstats.Coins.Value = coins -- change the players coins
  23.         end
  24.     elseif item == "Lazer" then -- item name, 2nd item
  25.         local coins = tonumber(player.leaderstats.Coins.Value) -- get the coins
  26.  
  27.         if coins >= item2price then -- check if the player has enough money to buy the coins
  28.             coins = coins - item2price -- minus the coins to the price
  29.             local i = item_folder.LaserGun:Clone() -- get & clone the gun
  30.             i.Parent = player.Backpack -- place the sword to the players inventory
  31.             player.leaderstats.Coins.Value = coins -- change the players coins
  32.         end
  33.     end
  34. end)
Advertisement
Add Comment
Please, Sign In to add comment