Advertisement
OnFireRobloxScriptin

Tool Handler Full Script

May 18th, 2024
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 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.         bought = false --Checks if player has already bought the item
  8.     },
  9.     ["Flash Light"] = { --Same thing but with a flash light
  10.         price = 750,
  11.         tool = game.ReplicatedStorage.Tools:WaitForChild("FlashLight"),
  12.         bought = false
  13.     },
  14.     ["Keycard"] = { --Same thing but with a key card
  15.         price = 1000,
  16.         tool = game.ReplicatedStorage.Tools:WaitForChild("SCP Card Level 4"),
  17.         bought = false
  18.     },
  19. }
  20.  
  21. --//Purchase
  22. BuyRE.OnServerEvent:Connect(function(player, item) --When the server recieves the remote event
  23.     local selectedItem = toolsDictionary[item] --Variable for the selected item
  24.     if selectedItem then --if selected item exists then
  25.         if player.leaderstats.Cash.Value >= selectedItem.price and selectedItem.bought == false then --if player has enough cash and has not bought the item yet then
  26.             player.leaderstats.Cash.Value -= selectedItem.price --subtract cash from the player
  27.             selectedItem.bought = true
  28.             local newItem = selectedItem.tool:Clone() --clone the tool player wants
  29.             newItem.Parent = player.Backpack --give tool to player
  30.         elseif selectedItem.bought == true then --if the player already bought the item
  31.             BuyRE:FireClient(player, item, "Max") --sends max error message
  32.         elseif player.leaderstats.Cash.Value < selectedItem.price then --if the player does not have enough cash
  33.             BuyRE:FireClient(player, item, "Cash") --sends cash error message
  34.         end
  35.     end
  36. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement