ShorelineLsuiza

Spawner

Jul 25th, 2024 (edited)
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | Gaming | 0 0
  1. ---------- VERSÃO ESTAVEL SPAWNER
  2.  
  3. local resources = game.ReplicatedStorage:WaitForChild("CraftingReplicatedStorage"):WaitForChild("Resources")
  4. local rnd = Random.new()
  5. local spawner = script.Parent
  6.  
  7. local isSpawning = false  -- Variável para controlar se está sendo feito um spawn
  8.  
  9. local function countResourcesInArea()
  10.     local count = 0
  11.     for _, resource in ipairs(workspace:GetChildren()) do
  12.         if resource:IsA("Model") and resource.Name == "Madeira" and resource:IsDescendantOf(spawner) then
  13.             count = count + 1
  14.         end
  15.     end
  16.     return count
  17. end
  18.  
  19. while true do
  20.     task.wait(5)  -- Espera de 2 segundos entre cada tentativa de spawn
  21.  
  22.     -- Verificar se não está atualmente spawnando e se não há recursos na área
  23.     if not isSpawning and countResourcesInArea() == 0 then
  24.         isSpawning = true
  25.  
  26.         -- Procurar pelo recurso específico "Madeira"
  27.         local woodResource = resources:FindFirstChild("Madeira")
  28.         if woodResource then
  29.             local newResource = woodResource:Clone()
  30.  
  31.             local randX = rnd:NextNumber(spawner.Position.X - spawner.Size.X/2, spawner.Position.X + spawner.Size.X/2)
  32.             local y = spawner.Position.Y
  33.             local randZ = rnd:NextNumber(spawner.Position.Z - spawner.Size.Z/2, spawner.Position.Z + spawner.Size.Z/2)
  34.  
  35.             newResource.Position = Vector3.new(randX, y, randZ)
  36.             newResource.Parent = workspace
  37.         else
  38.             warn("Recurso 'Madeira' não encontrado.")
  39.         end
  40.  
  41.         isSpawning = false
  42.     end
  43. end
  44.  
  45.  
  46. ----------------
  47.  
  48. SPAWN SOMENTE EM UMA AREA
  49.  
  50. local resources = game.ReplicatedStorage:WaitForChild("CraftingReplicatedStorage"):WaitForChild("Resources")
  51. local rnd = Random.new()
  52. local spawner = script.Parent
  53.  
  54. local isSpawning = false  -- Variável para controlar se está sendo feito um spawn
  55.  
  56. local function countResourcesInArea()
  57.     local count = 0
  58.     for _, resource in ipairs(workspace:GetChildren()) do
  59.         if resource:IsA("Corda") and resource:IsDescendantOf(spawner) then
  60.             count = count + 1
  61.         end
  62.     end
  63.     return count
  64. end
  65.  
  66. while true do
  67.     task.wait(1)
  68.  
  69.     -- Verificar se não está atualmente spawnando e se não há recursos na área
  70.     if not isSpawning and countResourcesInArea() == 0 then
  71.         isSpawning = true
  72.  
  73.         -- Procurar pelo recurso específico "corda"
  74.         local ropeResource = resources:FindFirstChild("Corda")
  75.         if ropeResource then
  76.             local newResource = ropeResource:Clone()
  77.  
  78.             local randX = rnd:NextNumber(spawner.Position.X - spawner.Size.X/2, spawner.Position.X + spawner.Size.X/2)
  79.             local y = spawner.Position.Y
  80.             local randZ = rnd:NextNumber(spawner.Position.Z - spawner.Size.Z/2, spawner.Position.Z + spawner.Size.Z/2)
  81.  
  82.             newResource.Position = Vector3.new(randX, y, randZ)
  83.             newResource.Parent = workspace
  84.         else
  85.             warn("Recurso 'corda' não encontrado.")
  86.         end
  87.  
  88.         isSpawning = false
  89.     end
  90. end
  91.  
Advertisement
Add Comment
Please, Sign In to add comment