(Solved) Help With Cash Collection System

I am making a game but I have a system where users can drop cash and others can pick it up but the dropping cash part works fine but the error comes when the users pick up the cash I don’t know how to solve this issue I also have a proximity prompt in the cash model that I want to use to pick up the cash here are my scripts:

This Is The Script that gets how much the player wants to drop and sends a remote event it is located in the dropper gui

local textBox = script.Parent.Parent.Amount
local button = script.Parent
local event = game.ReplicatedStorage.RemoteEvents.DropCash
local player = game.Players.LocalPlayer
local debounce = false

local function dropper()
	if (tonumber(textBox.Text)) then
		if not debounce then
			debounce = true
			if player.leaderstats.Money.Value > tonumber(textBox.Text) then
				player.leaderstats.Money.Value -= textBox.Text
				event:FireServer(textBox.Text)
				game.ReplicatedStorage.RemoteEvents.DropCash:FireServer(textBox.Text)
				task.wait(2)
				debounce = false
			end
		end
	end
end

button.MouseButton1Click:Connect(dropper)

This Script clones the money model and teleports it to the players position but I also want it to get when the user holds on the proximity prompt to collect the money and give the user the cash this script is in serverscriptservice

local event = game.ReplicatedStorage.RemoteEvents.DropCash

local og = game.ReplicatedStorage.Money.CustomAmount

local cash = og:Clone()

local function drop(player, amount)

local plr = game.Players:GetPlayerFromCharacter(player.Parent)

cash.Parent = game.Workspace.InGameMoney

cash.BillboardGui.TextLabel.Text = '$'..amount

cash.Position = player.Character.HumanoidRootPart.Position + Vector3.new(0,6,-3)

cash.Name = amount

end

event.OnServerEvent:Connect(drop)

Thanks!

1 Like

Local Script:

local textBox = script.Parent.Parent.Amount
local button = script.Parent
local event = game.ReplicatedStorage.RemoteEvents.DropCash
local player = game.Players.LocalPlayer
local debounce = false

local function dropper()
	if (tonumber(textBox.Text)) then
		if not debounce then
			debounce = true
			if player.leaderstats.Money.Value > tonumber(textBox.Text) then
				event:FireServer(textBox.Text)
			end
			task.wait(2)
			debounce = false
		end
	end
end

button.MouseButton1Click:Connect(dropper)

Server Script:

local event = game.ReplicatedStorage.RemoteEvents.DropCash

local og = game.ReplicatedStorage.Money.CustomAmount

local cash = og:Clone()

local function drop(player, amount)

cash.Parent = game.Workspace.InGameMoney

cash.BillboardGui.TextLabel.Text = '$'..amount

cash.Position = player.Character.HumanoidRootPart.Position + Vector3.new(0,6,-3)

cash.Name = amount

end

event.OnServerEvent:Connect(drop)

If you want to add a proximity prompt just do cash.ProximityPrompt.Triggered:Connect(function(player) and continue the code there.

1 Like

If you want to drop cash use a part and make that the cash you want to pick up then use a touched event on that part with the hit argument, then try getting the player and add their cash by whatever you like

I am using a part and a proximity prompt but the issue comes when you try to collect the money I get an error saying:

attempt to perform arithmetic (add) on number and nil

Here Is the script:

local event = game.ReplicatedStorage.RemoteEvents.DropCash

local og = game.ReplicatedStorage.Money.CustomAmount:Clone()

local cash = og:Clone()

local prompt = cash.ProximityPrompt

local function drop(player, amount)

	cash.BillboardGui.TextLabel.Text = '$'..tostring(amount)

	cash.Position = player.Character.HumanoidRootPart.Position + Vector3.new(0,6,-3)

	cash.Name = tostring(amount)
	
	cash.Parent = game.Workspace.InGameMoney
	
	player:WaitForChild('leaderstats').Money.Value = player:WaitForChild('leaderstats').Money.Value + amount
end

prompt.Triggered:Connect(drop)
event.OnServerEvent:Connect(drop)

You do not need to use an RemoteEvent for Proximity Prompts, especially since you are already using the remove event for something else. Create a normal script in the part you are cloning to give the player money.

local p = script.Parent.ProximityPrompt
p.Triggered:Connect(function(plr)
	local amount = script.Parent.BillboardGui.TextLabel.Text
	plr:WaitForChild("leaderstats").Money.Value = plr:WaitForChild("leaderstats").Money.Value + tonumber(amount)
	script.Parent:Destroy()
end)

Also, do not include a dollar sign in the same TextLabel as the amount, or it will cause the script to error. Use another TextLabel instead!

1 Like

This Works But It Only Works Once And The Money Cannot Be Dropped Again I get the error

BillboardGui is not a valid member of Part "101" 

clone the money, should fix the issue of it only working once.

Put the cash part in serverstorage, and have an event clone the money and put it into workspace. Create an event in replicated storage named drop and insert this as an script into serverscriptstorage.

event = game.ReplicatedStorage.drop
event.OnServerEvent:Connect(function(player,money)
	local c = game.ServerStorage.Part:Clone() -- Change "Part" to the name of the part.
	c.Position = player.Character.HumanoidRootPart.Position + Vector3.new(0,5,0)
	c.Parent = game.Workspace
	c.BillboardGui.TextLabel.Text = tostring(money)
end)

then, add a gui (which i presume you have) to startergui with an textbox (to add the amount) and a textbutton (to run the event), and then add a localscript to the textbutton.

script.Parent.MouseButton1Down:Connect(function()
	game.ReplicatedStorage.drop:FireServer(script.Parent.Parent.TextBox.Text)
end)	

hope this helps!

1 Like