|
|
|
|
| local CollectionService = game:GetService("CollectionService")
|
| local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
|
| local BiomeConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("BiomeConfig"))
|
|
|
|
|
| local RESPAWN_DELAY = 120
|
|
|
|
|
| local respawnQueue = {}
|
|
|
|
|
| local function onTreeSegmentRemoved(segment)
|
|
|
|
|
| local treeType = segment:GetAttribute("TreeType")
|
| if not treeType then return end
|
|
|
| local position = segment.Position
|
|
|
| if position.Y < 20 then
|
| table.insert(respawnQueue, {
|
| treeType = treeType,
|
| position = Vector3.new(position.X, 0, position.Z),
|
| timer = RESPAWN_DELAY,
|
| })
|
| end
|
| end
|
|
|
|
|
| CollectionService:GetInstanceRemovedSignal("TreeSegment"):Connect(function(segment)
|
|
|
| task.defer(function()
|
|
|
| end)
|
| end)
|
|
|
|
|
| local function bindSegmentTracking(segment)
|
| segment.Destroying:Connect(function()
|
| onTreeSegmentRemoved(segment)
|
| end)
|
| end
|
|
|
| CollectionService:GetInstanceAddedSignal("TreeSegment"):Connect(bindSegmentTracking)
|
| for _, segment in pairs(CollectionService:GetTagged("TreeSegment")) do
|
| bindSegmentTracking(segment)
|
| end
|
|
|
|
|
| task.spawn(function()
|
| while not _G.TreeSpawningComplete do
|
| task.wait(1)
|
| end
|
|
|
| while true do
|
| task.wait(5)
|
|
|
| local toRemove = {}
|
|
|
| for i, entry in ipairs(respawnQueue) do
|
| entry.timer = entry.timer - 5
|
|
|
| if entry.timer <= 0 then
|
|
|
| if _G.CreateTree then
|
| local rayResult = workspace:Raycast(
|
| Vector3.new(entry.position.X, 200, entry.position.Z),
|
| Vector3.new(0, -400, 0)
|
| )
|
|
|
| local groundY = 0
|
| if rayResult then
|
| groundY = rayResult.Position.Y
|
| end
|
|
|
| _G.CreateTree(entry.treeType, Vector3.new(entry.position.X, groundY, entry.position.Z))
|
| end
|
|
|
| table.insert(toRemove, i)
|
| end
|
| end
|
|
|
|
|
| for i = #toRemove, 1, -1 do
|
| table.remove(respawnQueue, toRemove[i])
|
| end
|
| end
|
| end)
|
|
|
| print("Respawn Manager initialized")
|
|
|