So I am trying to make it so when the parts prompt within a group has been activated it then adds a 1 value to the players leaderstats and then clones another one of its self from replicated storage and then positions its self in another location within a certain vector. It does all this perfectly until, the part clones and then it doesn’t do it again. And it’s not because the script doesn’t work…
the reason for it is because, it can’t run again… it just loops through the parts once the game is started and whatever parts are in there stay in there if they are destroyed they are gone, no matter if you clone them.
How would I get around this? Like making it loop again?
local folder = workspace:WaitForChild("Folder")
folder.DescendantAdded:Connect(function()
for _, prompt in ipairs(folder:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Triggered:Connect(function(player)
local part = prompt.Parent
print(player.Name.." picked up a coin!")
--do stuff
end)
end
end
end)
local ProximityPromptService = game:GetService(“ProximityPromptService”)
local TrashFolder = game.Workspace.Trash
local SandDollarsFolder = game.workspace:WaitForChild(“SandDollars”)
SandDollarsFolder.DescendantAdded:Connect(function()
for _, prompt in ipairs(SandDollarsFolder:GetDescendants()) do
if prompt:IsA(“ProximityPrompt”) then
prompt.Triggered:Connect(function(player)
local part = prompt.Parent
print(player.Name…" picked up a coin!")
local Sound = part.Coin_effect
player:WaitForChild(“leaderstats”).SandDollars.Value += 1
Sound:Play()
wait(2)
local NewPart = game.ReplicatedStorage.SandDollar:Clone()
NewPart.Position = Vector3.new(math.random(1,20), 0, math.random(1,20))
NewPart.Name = "SandDollar"
NewPart.Parent = SandDollarsFolder
part:Destroy()
end)
end
end
-- My Variables --
local ProximityPromptService = game:GetService("ProximityPromptService")
local TrashFolder = game.Workspace.Trash
local SandDollarsFolder = game.workspace:WaitForChild("SandDollars")
SandDollarsFolder.DescendantAdded:Connect(function()
for _, prompt in ipairs(SandDollarsFolder:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Triggered:Connect(function(player)
local part = prompt.Parent
print(player.Name.." picked up a coin!")
local Sound = part.Coin_effect
player:WaitForChild("leaderstats").SandDollars.Value += 1
Sound:Play()
wait(2)
local NewPart = game.ReplicatedStorage.SandDollar:Clone()
NewPart.Position = Vector3.new(math.random(1,20), 0, math.random(1,20))
NewPart.Name = "SandDollar"
NewPart.Parent = SandDollarsFolder
part:Destroy()
end)
end
end
end)