Hey! so im making a system for my game that generates items on set places around the map, i pretty much already got the full script done i only need to make the item spawn again
But for some reason the script i made isnt working, it doesnt detects when the item is removed, i already tried using Instance.Destroying, Parent.ChildRemoved and etc but it isnt working
Can anyone help me fix it?
function items(part)
while true do
task.wait(0.1)
if not part:GetAttribute("itemspawned") == true then
part:SetAttribute("itemspawned", true)
local itemfolder = game.ReplicatedStorage.faketools:GetChildren()
local item = itemfolder[math.random(math.max(#itemfolder, 1))]:Clone()
item.Parent = part
item:PivotTo(part:GetPivot())
print("bruh waaaaaaaaaat")
part.ChildRemoved:Wait() -- the line that the script stops
print("looooooooooooooooooooooooooool")
part:SetAttribute("itemspawned", false)
print("check mark")
task.wait(math.random(27, 127))
end
end
end
task.wait(0.5)
for i,v in pairs(workspace.spawns:GetChildren()) do
coroutine.wrap(items)(v)
end
game.ReplicatedStorage.events.faketool.OnServerEvent:Connect(function(plr, tool)
game.ReplicatedStorage.tools[tool]:Clone().Parent = plr.Backpack
end)