Script for Spawning in Multiple Models not working

I have all of my Objects in ServerStorage in a folder called “Trash” this script is supposed to put them all in workspace, but it doesn’t :frowning:

local ServerStorage = game.ServerStorage
local Trash = game.ServerStorage.Trash

while true do
local bins = Trash:GetChildren("P2")
bins.Parent = game.Workspace
wait(300)
end
local ServerStorage = game:GetService("ServerStorage")
local Trash = game.ServerStorage:WaitForChild("Trash")

while task.wait() do
	local bins = Trash:WaitForChild("P2")
	bins.Parent = game.Workspace
	task.wait(300)
end

This only adds one of the models named P2 to the Workspace.

Okay, so you have multiple, I wasn’t sure since “GetChildren(“P2”)” isn’t valid.

you could try this

game.ServerStorage.Trash:Clone().Parent = workspace

local ServerStorage = game:GetService("ServerStorage")
local Trash = game.ServerStorage:WaitForChild("Trash")

while task.wait() do
	local bins = Trash:GetChildren()
	for i, v in pairs(bins) do
		if v.Name == "P2" then
			v.Parent = game.Workspace
			task.wait(300)
		end
	end
end

Yes. I don’t know how you’d do what I want to do.

I provided what you want to do above.

This works, but when I add the task.wait(300) it doesn’t?

task.wait(300) causes a delay for 300 seconds, you may want to decrease it. You may also want to move it.

local ServerStorage = game:GetService("ServerStorage")
local Trash = game.ServerStorage:WaitForChild("Trash")

while task.wait() do
	local bins = Trash:GetChildren()
	for i, v in pairs(bins) do
		if v.Name == "P2" then
			v.Parent = game.Workspace
		end
	end
	task.wait(300)
end

You may prefer it like this.