Advertisement
TMarius01

Wallet System

May 20th, 2024 (edited)
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.10 KB | None | 0 0
  1. ---- Main tool script (local script inside tool) ----
  2.  
  3. local player = game.Players.LocalPlayer
  4. local PlayerGui = player:WaitForChild("PlayerGui")
  5. local WalletGui = PlayerGui:WaitForChild("WalletGui")
  6.  
  7. local open = WalletGui:WaitForChild("Open")
  8.  
  9. script.Parent.Activated:Connect(function()
  10.     if open.Value == false then
  11.         open.Value = true
  12.         WalletGui.MainFrame:TweenPosition(UDim2.new(0.5, 0,0.5, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 1, true)
  13.     else
  14.         open.Value = false
  15.         WalletGui.MainFrame:TweenPosition(UDim2.new(0.5, 0,1.27, 0), Enum.EasingDirection.In, Enum.EasingStyle.Back, 1, true)
  16.     end
  17. end)
  18.  
  19. script.Parent.Unequipped:Connect(function()
  20.     open.Value = false
  21.     WalletGui.MainFrame:TweenPosition(UDim2.new(0.5, 0,1.27, 0), Enum.EasingDirection.In, Enum.EasingStyle.Back, 1, true)
  22. end)
  23.  
  24. ---- Money display script (script inside tool) ----
  25.  
  26. local FormatNumber = require(game.ReplicatedStorage.Modules.FormatNumber)
  27. local formatter = FormatNumber.NumberFormatter.with()
  28.  
  29. script.Parent.Equipped:Connect(function()
  30.     local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
  31.     print(player)
  32.     if player then
  33.         script.Parent.Handle.BillboardGui.TextLabel.Text = "$"..formatter:Format(player.Money.Value)
  34.         player.Money:GetPropertyChangedSignal("Value"):Connect(function()
  35.             script.Parent.Handle.BillboardGui.TextLabel.Text = "$"..formatter:Format(player.Money.Value)
  36.         end)
  37.     end
  38. end)
  39.  
  40. ---- Main UI script (local script inside ScreenGui) ----
  41.  
  42. local player = game.Players.LocalPlayer
  43.  
  44. local FormatNumber = require(game.ReplicatedStorage.Modules.FormatNumber)
  45. local formatter = FormatNumber.NumberFormatter.with()
  46.  
  47. local db = false
  48.  
  49. script.Parent.MainFrame.CloseButton.MouseButton1Click:Connect(function()
  50.     script.Parent.Open.Value = false
  51.     script.Parent.MainFrame:TweenPosition(UDim2.new(0.5, 0,1.27, 0), Enum.EasingDirection.In, Enum.EasingStyle.Back, 1, true)
  52. end)
  53.  
  54. for i, v in ipairs(script.Parent.MainFrame.Options:GetChildren()) do
  55.     if v:IsA("TextButton") then
  56.         if tonumber(v.Name) then
  57.             v.MouseButton1Click:Connect(function()
  58.                 if db == false then
  59.                     db = true
  60.                
  61.                     local response = game.ReplicatedStorage.DropCash:InvokeServer(tonumber(v.Name))
  62.                     print(response)
  63.                    
  64.                     if response ~= "success" then
  65.                         script.Parent.MainFrame.CustomAmountBox.Text = response
  66.                     end
  67.                    
  68.                     wait(1)
  69.                        
  70.                     db = false
  71.                 end
  72.             end)
  73.         end
  74.     end
  75. end
  76.  
  77. script.Parent.MainFrame.DropButton.MouseButton1Click:Connect(function()
  78.     if script.Parent.MainFrame.CustomAmountBox.Text ~= "" then
  79.         if db == false then
  80.             db = true
  81.            
  82.             local response = game.ReplicatedStorage.DropCash:InvokeServer(script.Parent.MainFrame.CustomAmountBox.Text)
  83.             print(response)
  84.            
  85.             if response ~= "success" then
  86.                 script.Parent.MainFrame.CustomAmountBox.Text = response
  87.             end
  88.            
  89.    
  90.             wait(2)
  91.  
  92.             db = false
  93.         end
  94.     end
  95. end)
  96.  
  97. script.Parent.MainFrame.CustomAmountBox.FocusLost:Connect(function()
  98.     if tonumber(script.Parent.MainFrame.CustomAmountBox.Text) then
  99.         script.Parent.MainFrame.CustomAmountBox.Text = script.Parent.MainFrame.CustomAmountBox.Text
  100.     else
  101.         script.Parent.MainFrame.CustomAmountBox.Text = ""
  102.     end
  103. end)
  104.  
  105. script.Parent.MoneyDisplay.Text = "$"..formatter:Format(player.Money.Value)
  106. player.Money:GetPropertyChangedSignal("Value"):Connect(function()
  107.     script.Parent.MoneyDisplay.Text = "$"..formatter:Format(player.Money.Value)
  108. end)
  109.  
  110. ---- Pickup script (local script inside StarterPlayerScripts)
  111.  
  112. local player = game.Players.LocalPlayer
  113. local mouse = player:GetMouse()
  114. local UIS = game:GetService("UserInputService")
  115.  
  116. local PlayerGui = player:WaitForChild("PlayerGui")
  117. local PickupGui = PlayerGui:WaitForChild("PickupGui")
  118.  
  119. UIS.InputChanged:Connect(function()
  120.     if mouse.Target then
  121.         if mouse.Target.Parent:FindFirstChild("Handle") and mouse.Target.Parent.Name == "MoneyStack" then
  122.             PickupGui.Enabled = true
  123.             PickupGui.Adornee = mouse.Target.Parent.Handle
  124.         else
  125.             PickupGui.Enabled = false
  126.             PickupGui.Adornee = nil
  127.         end
  128.     else
  129.         PickupGui.Enabled = false
  130.         PickupGui.Adornee = nil
  131.     end
  132. end)
  133.  
  134. UIS.InputBegan:Connect(function(key, g)
  135.     if g then
  136.         return
  137.     end
  138.     if key.KeyCode == Enum.KeyCode.E then
  139.         if mouse.Target then
  140.             local part = mouse.Target
  141.             if part.Parent:FindFirstChild("Handle") and part.Parent.Name == "MoneyStack" then
  142.                 if part.Parent:FindFirstChild("Amount") then
  143.                     if (player.Character.HumanoidRootPart.Position - part.Position).Magnitude <= 25 then
  144.                         game.ReplicatedStorage.PickupCash:FireServer(part, part.Parent.Amount.Value)
  145.                     end
  146.                 end
  147.             end
  148.         end
  149.     end
  150. end)
  151.  
  152. ---- Event Handling script (script inside ServerScriptService) ----
  153.  
  154. game.Players.PlayerAdded:Connect(function(player)
  155.     local Money = Instance.new("IntValue")
  156.     Money.Name = "Money"
  157.     Money.Parent = player
  158. end)
  159.  
  160. function dropCash(player, amount)
  161.     if player and amount then
  162.         local newCash = script.MoneyStack:Clone()
  163.         newCash.Amount.Value = amount
  164.         newCash.Handle.BillboardGui.TextLabel.Text = "$"..formatter:Format(amount)
  165.        
  166.         local dropOffset = 2.5
  167.         local newPos = player.Character.Head.Position + player.Character.Head.CFrame.lookVector*dropOffset
  168.        
  169.         newCash.Parent = workspace
  170.         newCash.Handle.CFrame = CFrame.new(newPos,newPos+player.Character.Head.CFrame.lookVector)
  171.         newCash.Handle.Velocity = player.Character.Head.CFrame.lookVector*8
  172.     end
  173. end
  174.  
  175. game.ReplicatedStorage.DropCash.OnServerInvoke = function(player, amount)
  176.     print(player, amount)
  177.     if amount then
  178.         if tonumber(amount) then
  179.             amount = tonumber(amount)
  180.             if amount >= 10 then
  181.                 if amount <= 25000 then
  182.                     if player.Money.Value >= amount then
  183.                         if player.Character then
  184.                             player.Money.Value -= amount
  185.                             dropCash(player, amount)
  186.                             return "success"
  187.                         end
  188.                     else
  189.                         return "You don't have this much money!"
  190.                     end
  191.                 else
  192.                     return "You must drop less than $25,000!"
  193.                 end
  194.             else
  195.                 return "You must drop more than $10!"
  196.             end
  197.         else
  198.             return "Invalid Number!"
  199.         end
  200.     else
  201.         return "Invalid Number!"
  202.     end
  203. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement