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