I am not familiar with scripting.
I have an item spawner script that spawns the item I need however the spawner does not stop AND the items will spawn in the same spot multiple times. I need help stopping or disabling the script once the number of items I want to spawn has been reached and for those spawned items not to overlap.
This is the code I have so far that works flawlessly.
local spawns = workspace.ItemSpawns
local items = game.ReplicatedStorage.Items
local seconds = 3
local function chooseSpawn ()
local _spawn = spawns:GetChildren()[math.random(1,#spawns:GetChildren())]
return _spawn
end
local function chooseItem()
local item = items:GetChildren()[math.random(1,#items:GetChildren())]
return items
end
while wait (seconds) do
local _spawn = chooseSpawn()
local items = chooseItem()
local clone = items:Clone()
clone.Parent = workspace
clone.Corn.corng.CFrame = _spawn.CFrame * CFrame.new(0,5,0)
end
after adding the line āif clone is >= 7ā the code stopped working entirely and giving the error, "ServerScriptService.SpawnerScript:20: Expected āthenā when parsing if statement, got ābreakā "
local spawns = workspace.ItemSpawns
local items = game.ReplicatedStorage.Items
local clone = items:Clone()
local seconds = 3
local function chooseSpawn ()
local _spawn = spawns:GetChildren()[math.random(1,#spawns:GetChildren())]
return _spawn
end
local function chooseItem ()
local item = items:GetChildren()[math.random(1,#items:GetChildren())]
return items
end
while wait (seconds) do
if clone is >= 7
break
else if clone < 7 do
local _spawn = chooseSpawn()
local items = chooseItem()
clone.Parent = workspace
clone.Corn.corng.CFrame = _spawn.CFrame * CFrame.new(0,5,0)
end
end
end
end
I would appreciate it if anyone could point me in the right direction of how to stop the spawner script and the items overlapping. Thank you.