So I made this gatherable items script where it uses collection service (To avoid individual scripts hassle) and then whenever the prompt inside the tagged objects are triggered, it should remove the items and place it inside the inventory.
But I made chest that when it gets destroyed, it spawns the pickable items around it (The ones with prompts inside it) it does clones the items, however, The prompts won’t trigger. I also noticed that objects that are already placed in the workspace works while the cloned ones doesn’t. I’ll be sending video clips as well as source codes below for more clarification.
Working items in workspace
Below are the items that’s already in the workspace (It works, it gets deleted upon prompt trigger)
1st video source code
local SetTags = CollectionService:GetTagged("PickUp")
local Debounce = false
for _,v in pairs(SetTags) do
if v:IsA("Model") or v:IsA("BasePart") or v:IsA("MeshPart") then
for i, v in pairs(v:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("MeshPart") then
if v:FindFirstChildWhichIsA("ProximityPrompt") then
local Prompt = v:WaitForChild("prompt")
Prompt.Triggered:Connect(function(Player)
if Debounce == false then
Debounce = true
game.Debris:AddItem(v, .1)
Debounce = false
end
end)
end
end
end
end
end
Not working prompts cloned items
While this are the cloned items (It clones the object however, The prompts won’t trigger and get the objects deleted.)
2nd video source code
if v:IsA("Model") then
for i,Chest in pairs (v:GetChildren()) do
if Chest:IsA("BasePart") or Chest:IsA("MeshPart") then
local Debounce = false
Chest.Touched:Connect(function(PartCollider)
if PartCollider.Parent:FindFirstChildWhichIsA("Humanoid") then
if PartCollider:IsA("BasePart") or PartCollider:IsA("MeshPart") then
if Debounce == false then
Debounce = true
for i = 1,9 do
wait()
print("Chest Touched!")-- prints if the Chest is touched
local ChosenObjects = RandomItems[math.random(1,#RandomItems)]:Clone() -- Clones the items and spawns it around the chest object.
local SetFrame = ChosenObjects:SetPrimaryPartCFrame(Chest.CFrame) -- Setting the primary part CFrame since the one im cloning is a model.
SetFrame = Chest.CFrame -- Sets the object CFrame to Chest CFrame
ChosenObjects.Parent = game.Workspace
end
v:Destroy()
Debounce = false
end
end
end
end)
end
end
end
end
Any help would be really appreciated!