Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------- VERSÃO ESTAVEL SPAWNER
- local resources = game.ReplicatedStorage:WaitForChild("CraftingReplicatedStorage"):WaitForChild("Resources")
- local rnd = Random.new()
- local spawner = script.Parent
- local isSpawning = false -- Variável para controlar se está sendo feito um spawn
- local function countResourcesInArea()
- local count = 0
- for _, resource in ipairs(workspace:GetChildren()) do
- if resource:IsA("Model") and resource.Name == "Madeira" and resource:IsDescendantOf(spawner) then
- count = count + 1
- end
- end
- return count
- end
- while true do
- task.wait(5) -- Espera de 2 segundos entre cada tentativa de spawn
- -- Verificar se não está atualmente spawnando e se não há recursos na área
- if not isSpawning and countResourcesInArea() == 0 then
- isSpawning = true
- -- Procurar pelo recurso específico "Madeira"
- local woodResource = resources:FindFirstChild("Madeira")
- if woodResource then
- local newResource = woodResource:Clone()
- local randX = rnd:NextNumber(spawner.Position.X - spawner.Size.X/2, spawner.Position.X + spawner.Size.X/2)
- local y = spawner.Position.Y
- local randZ = rnd:NextNumber(spawner.Position.Z - spawner.Size.Z/2, spawner.Position.Z + spawner.Size.Z/2)
- newResource.Position = Vector3.new(randX, y, randZ)
- newResource.Parent = workspace
- else
- warn("Recurso 'Madeira' não encontrado.")
- end
- isSpawning = false
- end
- end
- ----------------
- SPAWN SOMENTE EM UMA AREA
- local resources = game.ReplicatedStorage:WaitForChild("CraftingReplicatedStorage"):WaitForChild("Resources")
- local rnd = Random.new()
- local spawner = script.Parent
- local isSpawning = false -- Variável para controlar se está sendo feito um spawn
- local function countResourcesInArea()
- local count = 0
- for _, resource in ipairs(workspace:GetChildren()) do
- if resource:IsA("Corda") and resource:IsDescendantOf(spawner) then
- count = count + 1
- end
- end
- return count
- end
- while true do
- task.wait(1)
- -- Verificar se não está atualmente spawnando e se não há recursos na área
- if not isSpawning and countResourcesInArea() == 0 then
- isSpawning = true
- -- Procurar pelo recurso específico "corda"
- local ropeResource = resources:FindFirstChild("Corda")
- if ropeResource then
- local newResource = ropeResource:Clone()
- local randX = rnd:NextNumber(spawner.Position.X - spawner.Size.X/2, spawner.Position.X + spawner.Size.X/2)
- local y = spawner.Position.Y
- local randZ = rnd:NextNumber(spawner.Position.Z - spawner.Size.Z/2, spawner.Position.Z + spawner.Size.Z/2)
- newResource.Position = Vector3.new(randX, y, randZ)
- newResource.Parent = workspace
- else
- warn("Recurso 'corda' não encontrado.")
- end
- isSpawning = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment