Hello, i have this issue where i created a script that auto spawns objects on top of the Baseplate,
I set the despawn time to 600 seconds ‘10 minutes’ after it spawns. But my Objects despawn way quicker. maybe less than 10 seconds.
Here is my spawn code:
local AnimalFolder = game.ServerStorage.Animals
local tree = AnimalFolder.Tree
local destroyTime = 600
local waitDelay = 0.01
if game.Workspace.Baseplate == nil then
return
end
local newFolder = Instance.new("Folder")
newFolder.Parent = game.Workspace
newFolder.Name = "Workspace.Tree"
local function CreateNewPart()
local NewTree = tree:Clone()
if not newFolder:IsA("Folder") then
return
end
NewTree.Parent = newFolder
local newCFrame = CFrame.new((math.random((-game.Workspace.Baseplate.Size.X / 2), (game.Workspace.Baseplate.Size.X / 2))), 9.514, (math.random((-game.Workspace.Baseplate.Size.Z / 2), (game.Workspace.Baseplate.Size.Z / 2))))
NewTree:PivotTo(newCFrame)
game.Debris:AddItem(NewTree, destroyTime)
end
local amount = 200
local currentAmount = 0
game.Workspace.ChildAdded:Connect(function(child)
print(child.Name)
end)
newFolder.ChildRemoved:Connect(function(child)
if child.Name == ("Tre") then
currentAmount = currentAmount - 1
end
end)
while true do
if currentAmount < amount then
currentAmount = currentAmount + 1
CreateNewPart()
print(currentAmount)
end
if currentAmount == amount then
end
task.wait(waitDelay)
end
If you have a fix, Please say. It’s apreciated.