I've been working on a script, it's to teleport a tree(I'm going to add rocks as well) to a part called "ItemSpawns." It confuses me a bit because, one, I have to teleport as many trees as there are ItemSpawns left. And, two, teleporting two parts. (The trees need the 2nd part to be chopped down)
Here is the script-
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tree = ReplicatedStorage:WaitForChild("Tree").Trunk
local TerrainSpawnFolder = workspace:WaitForChild("TerrainSpawns")
local ItemSpawns = TerrainSpawnFolder:GetChildren()
local AvaiableItemSpawns = math.random(1,#ItemSpawns)
--Spawns Trees--
local ClonedTree = Tree:Clone()
ClonedTree.Parent = workspace
for i, ClonedTree in pairs(AvaiableItemSpawns) do
if ClonedTree then
--spawn tree
ClonedTree.CFrame = AvaiableItemSpawns.CFrame
table.remove(AvaiableItemSpawns, i)
end
if not Tree then
-- Don't spawn the tree
end
end
It's giving me errors on line 15 like " ServerScriptService.GameManager.PlanetTerrain.TerrainSpawner:11: bad argument #1 to 'pairs' (table expected, got number)"
I understand why it's saying this, but, this is the only way I can think of doing this.
If you can help then, Thx

2 comments
sorry i dont have an answer but just 1 question, why is AvaibleItemSpawns a random number between 1 and ItemSpawns? if there were 10 spawns you could potentially only teleport 1. you say you have to teleport as many trees as there are item spawns. if i read it all wrong forgive me, but it seems to be a flaw?
also the "table expected, got number" error occurs because its just a number with no significant value. its a random number. you need a table of all your spawn points.