How would i make a money pickup system?

Ive tried everything to make a simple system to when you press a proximity prompt, you get money, and a part disappears. coming back later after for instance - 30 seconds it comes back and you can pick it up again.

Ive tried something like the code below:

But it does not work, nothing worked and ive tried this for a long time, any guidance / preexisting things?

Looking to completely scrap this:

local MoneyBill = game.Workspace:WaitForChild("MoneyBill")
local ProximityPrompt = MoneyBill:FindFirstChildOfClass("ProximityPrompt")
local RespawnTime = 60 -- time before respawn
local IsPickedUp = false

local function OnPromptTriggered(player)
    if IsPickedUp then
        return
    end

    local playerBloodBux = player:FindFirstChild("BloodBux")

    if not playerBloodBux then
        playerBloodBux = Instance.new("IntValue")
        playerBloodBux.Name = "BloodBux"
        playerBloodBux.Parent = player
    end

    playerBloodBux.Value = playerBloodBux.Value + 200  

    IsPickedUp = true
    MoneyBill:Destroy() 

    wait(RespawnTime)  

    local newMoneyBill = MoneyBill:Clone()
    newMoneyBill.Parent = game.Workspace 

    IsPickedUp = false
    ProximityPrompt.Parent = newMoneyBill
end

ProximityPrompt.Triggered:Connect(OnPromptTriggered)

3 Likes

You are trying to implement recursion with something that destroys the component it started with, so it can’t clone anything. The initial MoneyBill and ProximityPrompt parts are destroyed on its first go around. If you know how to utilize modulescripts or know what Object Oriented Programming is, you could create a dollar object with the proximityprompt and spawn it on a loop of a given timeframe.

1 Like

Here’s a way that I did it by making a money spawner.

--> Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--> Assets
local Assets = ReplicatedStorage:WaitForChild("Assets")
local Money = Assets:WaitForChild("Money")

--> Spawns
local MoneySpawns = workspace:WaitForChild("MoneySpawns")

--> Functions
local function FindEmptySpawn()
	local EmptySpawn = nil
	
	for _, v in pairs(MoneySpawns:GetChildren()) do
		if v:GetAttribute("Spawned") == false then
			EmptySpawn = v
		end
	end
	
	return EmptySpawn
end

local function SpawnMoney()
	local MoneySpawn = FindEmptySpawn()
	
	if MoneySpawn == nil then return end -- No Opened Spawns.
	
	local Worth = math.random(1, 60)
	local MoneyPart = Money:Clone()
	
	local Pickup = MoneyPart:WaitForChild("Pickup")
	local WorthValue = MoneyPart:WaitForChild("Worth")
	
	WorthValue.Value = Worth
	
	MoneyPart.Parent = workspace
	MoneyPart.CFrame = MoneySpawn.CFrame
	MoneySpawn:SetAttribute("Spawned", true)
	
	Pickup.Enabled = true
	
	Pickup.Triggered:Connect(function(player)
		local leaderstats = player:WaitForChild("leaderstats")
		local PlayerMoney = leaderstats:WaitForChild("Money")
		
		PlayerMoney.Value += WorthValue.Value
		
                MoneySpawn:SetAttribute("Spawned", false)
		MoneyPart:Destroy()
	end)
end

while task.wait(10) do
	SpawnMoney()
end

image_2023-08-26_010609012

3 Likes
local MoneyBill = game.Workspace:WaitForChild("MoneyBill")
local ProximityPrompt = MoneyBill:FindFirstChildOfClass("ProximityPrompt")
local RespawnTime = 60 -- time before respawn
local IsPickedUp = false

local function OnPromptTriggered(player)
    if IsPickedUp == true then
        return
    end

    local playerBloodBux = player:FindFirstChild("BloodBux")

    if not playerBloodBux then
        playerBloodBux = Instance.new("IntValue")
        playerBloodBux.Name = "BloodBux"
        playerBloodBux.Parent = player
    end

    playerBloodBux.Value += 200

    IsPickedUp = true
    local ProximityClone = ProximityPrompt:Clone()
    task.wait()
    MoneyBill:Destroy() 

    wait(RespawnTime)  

    local newMoneyBill = MoneyBill:Clone()
    newMoneyBill.Parent = game.Workspace 

    IsPickedUp = false
    ProximityClone.Parent = newMoneyBill
end

ProximityPrompt.Triggered:Connect(OnPromptTriggered)
4 Likes

You can parent the money part to replicated storage and after 30 seconds clone it to workspace and then delete the original.

2 Likes

how would i set this up? I see your image and I see a “GetAttribute” thing… Ive added the script in server script service and its all like yours. I dont know whats wrong, sorry for seeming dumb - im new to this

I yeld to Blade’s epic scripting skills …

Go to the properties tab of the spawns, scroll all the way down to attributes and click the Plus icon.
Change the type to a boolean value and name it “Spawned”

1 Like

it does not seem to be working, ive added the attribute and everything… odd

I have open sourced my place so you can see exactly everything with the parts and stuff

3 Likes

I did one just like this, this is really good work.
As long as the item can just drop like that.

2 Likes

yes it works, its really nice. thanks, like it because i can add my own custom proximity prompt

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.