Advertisement
OnFireRobloxScriptin

Buy Item Serverscript for Part 2 of the series

Mar 26th, 2024
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.15 KB | None | 0 0
  1. --//Variables
  2. local BuyRE = game.ReplicatedStorage:WaitForChild("Buy") --Variable for the buy remote event
  3. local classicsword = game.ReplicatedStorage.Tools:WaitForChild("ClassicSword") --Variable for tool stored under the replicated storage
  4.  
  5. --//Purchase
  6. BuyRE.OnServerEvent:Connect(function(player, item) --When the server recieves the remote event
  7.     if item == "Classic Sword" then --Check if the string recieved matches
  8.         if player.leaderstats.Cash.Value >= 500 then --Check if player has equal or more than $500 <- You can change the 500 to how much you want it to cost
  9.             player.leaderstats.Cash.Value -= 500 --Deduct $500 <- You can change the 500 to how much you want to deduct
  10.             local newitem = classicsword:Clone() --Create a clone of the tool/item
  11.             newitem.Parent = player.Backpack --Give tool/item to the player
  12.         else --Any other scenario where the player does NOT have equal to or over $500
  13.             print("Not enough cash") --Print error message
  14.         end
  15.     end
  16. end)
  17.  
  18. --//NOTE:
  19. --This script is not fully complete, it is just a framework and a setup for the next parts in the working shop series. You can use it it you are currently on part 2 of the series.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement