Advertisement
OnFireRobloxScriptin

Buy Item Serverscript for Part 3 of the series

Apr 20th, 2024
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. --//Variables
  2. local BuyRE = game.ReplicatedStorage:WaitForChild("Buy") --Variable for the buy remote event
  3. local toolsDictionary = { --Variable for Tool Dictionary
  4.     ["Classic Sword"] = { --New item in Tool Dictionary
  5.         price = 500, --Price of item
  6.         tool = game.ReplicatedStorage.Tools:WaitForChild("ClassicSword") --Physical location of item
  7.     },
  8.     ["Flash Light"] = { --Same thing but with a flash light
  9.         price = 750,
  10.         tool = game.ReplicatedStorage.Tools:WaitForChild("FlashLight")
  11.     }
  12. }
  13.  
  14. --//Purchase
  15. BuyRE.OnServerEvent:Connect(function(player, item) --When the server recieves the remote event
  16.     local selectedItem = toolsDictionary[item] --Variable for the selected item
  17.     if selectedItem then --if selected item exists then
  18.         if player.leaderstats.Cash.Value >= selectedItem.price then --if player has enough cash then
  19.             player.leaderstats.Cash.Value -= selectedItem.price --subtract cash from the player
  20.             local newItem = selectedItem.tool:Clone() --clone the tool player wants
  21.             newItem.Parent = player.Backpack --give tool to player
  22.         end
  23.     end
  24. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement