как сделать рандомный спавн предметов в пределах зоны?я расскажу и покажу!

Аватар автора
Atremn
скрипт: local ReplicatedStorage = game:GetService("ReplicatedStorage") local Workspace = game:GetService("Workspace") -- Настройки local itemTemplate = ReplicatedStorage:WaitForChild("ItemTemplate") -- Шаблон предмета local spawnRegion = Workspace:WaitForChild("SpawnRegion") -- Part local spawnInterval = 5 local maxItems = 10 -- Хранение активных предметов local activeItems = {} -- Получаем границы зоны local function getRandomPositionInRegion(regionPart) local size = regionPart.Size local position = regionPart.Position local minX = position.X - size.X / 2 local maxX = position.X + size.X / 2 local minY = position.Y local maxY = position.Y + size.Y local minZ = position.Z - size.Z / 2 local maxZ = position.Z + size.Z / 2 return Vector3.new( math.random() * (maxX - minX) + minX, math.random() * (maxY - minY) + minY, math.random() * (maxZ - minZ) + minZ ) end -- Функция спавна local function spawnItemInZone() if ﹥= maxItems then return end local item = itemTemplate:Clone() item.Position = getRandomPositionInRegion(spawnRegion) item.Parent = Workspace table.insert(activeItems, item) -- Удаляем из списка при удалении item.AncestryChanged:Connect(function(_, parent) if not parent then for i, v in ipairs(activeItems) do if v == item then table.remove(activeItems, i) break end end end end) end -- Основной цикл while true do spawnItemInZone() wait(spawnInterval) end

0/0


0/0

0/0

0/0