Moving Model to Workspace breaks script?

Now the clone script is broken spamming a lot of errors:

Error:

Line of Code:
local newTrash = selectTrash():Clone()

That’s because it’s expecting the function to return an instance, you need to handle that by checking if the function returned something before attempting to clone it.

local oldTrash = selectTrash()
if oldTrash then
	local newTrash = oldTrash:Clone()
end
2 Likes

So it would be like this?

for i=1,Random.new():NextInteger(1,3) do
							local oldTrash = selectTrash()
							if oldTrash then
								local newTrash = oldTrash:Clone()
							
							newTrash.CFrame = CFrame.new((CFrame.new(ray.Position) * CFrame.new(0, newTrash.Size.Y / 2, 0)).Position, ray.Position + ray.Normal)
							newTrash.CFrame *= CFrame.Angles(
								math.rad(math.random(-360,360)),
								math.rad(math.random(-360,360)),
								math.rad(math.random(-360,360))
							)
							newTrash.Anchored = false
							newTrash.CanCollide = true
							newTrash.Parent = workspace.World.Trash
							newTrash:SetNetworkOwner(nil)
							script.Dampening:Clone().Parent = newTrash
						end
					end
					end
				end

I have tried that but now its not spawning anything

That means the trash folder is always empty.

How do I fix this then, is there any solution to this problem?

There is nothing in the folder, of course it will do nothing.
Simply just let the script clone items to workspace instead of moving them to workspace.