Package won't spawn?

  1. I want it to loop every 10-20 seconds and pick a package from a model in ServerStorage and spawn it on a conveyor.

  2. The issue is that it isn’t even spawning. I waited 1 minutes-

  3. I have tried searching the problem and trying to find an error but found nothing? Either I don’t understand or there is an error.

Code

local Spawner = game.Workspace.Spawner
local Players = game:GetService("Players")

--// Main
while wait(math.random(10,20)) do
	Players.PlayerAdded:Connect(function(player)
		local Packages = game:GetService("ServerStorage").Packages:GetChildren()
		local randomPackage = Packages[math.random(1,#Packages)]:Clone()
		randomPackage.Parent = workspace
		randomPackage.Handle.CFrame = Spawner.CFrame
		
		if randomPackage.Handle.Parent == player.Backpack then
			print("Backpack")
		else
            wait(10)
			randomPackage:Destroy()
		end
	end)
end

Anybody know?

Is it a model? Can I see the ServerStorage?
and… it won’t work at all ngl.

Players.PlayerAdded:Connect(function(player)
while wait(math.random(10,20)) do

end
end)

Would be correct way.

1 Like

Screen Shot 2021-04-21 at 4.21.57 PM

Yeah you lined it wrong here
grafik

Swap this 2 lines

grafik
and this 2 at end.

It worked but one more thing. I want it to NOT destroy if the tool is in the players backpack but it destroys anyways. Do you know how to fix that? It’s in the code.

if randomPackage.Parent == player.Backpack or randomPackage.Parent == player.Character then
1 Like

Thanks a lot! So much help and a new thing learned! :smiley: