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)
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.
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
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!
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.