How do I make a part spawn at multiple positions at the same time?

I’m trying to make a single script create multiple parts at my models position but I can’t make the part’s position go to all the models at the same time.

for i, v in pairs(animalFolder:GetDescendants()) do
	
	wait(math.random(1,10))
	local part = Instance.new("MeshPart", v)
	local click = Instance.new("ClickDetector", part)
	local clicksound= Instance.new("Sound")

    clicksound.SoundId = soundid
	part.BrickColor = BrickColor.new("Medium brown")
	part.Size = Vector3.new(2,.5,.5)
	
	
	
		
	click.MaxActivationDistance = 32
	part.Position = v.body.Position --[[When I do this I get the error message "body is not a valid member of MeshPart "Workspace.ANIMALS.gurt.body"". So I tried this: v.Position and got the error message "Position is not a valid member of Model "Workspace.ANIMALS.gurt"" ]]

	click.MouseClick:Connect(function(player)
		addNmbr:FireClient(player)
		poopsound:Play()
		poop:Destroy()	
		
	end)	
end

I tried a single position and they spawned there, but is there any way I could get them to spawn at all of the models positions?

1 Like

Try this out:

for i, v in pairs(animalFolder:GetDescendants()) do

	wait(math.random(1,10))
	local part = Instance.new("MeshPart", v)
	local click = Instance.new("ClickDetector", part)
	local clicksound= Instance.new("Sound")

	clicksound.SoundId = soundid
	part.BrickColor = BrickColor.new("Medium brown")
	part.Size = Vector3.new(2,.5,.5)




	click.MaxActivationDistance = 32
	--@ guessing that v:IsA("Model")
	part.CFrame = v:GetPivot()

	click.MouseClick:Connect(function(player)
		addNmbr:FireClient(player)
		poopsound:Play()
		poop:Destroy()	

	end)	
end
1 Like

This worked! But is there any way that I could make the for i loop random?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.