Шаблон большого мира Roblox с биомами, животными, транспортом и сундуками
-- Улучшенный и расширяемый код для спавна любых визуальных объектов из ReplicatedStorage local ReplicatedStorage = game:GetService("ReplicatedStorage") local Workspace = game:GetService("Workspace")
-- Универсальная функция для спавна объекта из указанной папки local function spawnVisualObject(folderName, objectName, position, parent) local folder = ReplicatedStorage:FindFirstChild(folderName) if not folder then warn("Folder '"..folderName.."' not found in ReplicatedStorage") return nil end local template = folder:FindFirstChild(objectName) if not template then warn("Object '"..objectName.."' not found in ReplicatedStorage/"..folderName) return nil end local clone = template:Clone() clone.Parent = parent or Workspace if clone:IsA("Model") and clone.PrimaryPart then clone:SetPrimaryPartCFrame(CFrame.new(position)) elseif clone:IsA("BasePart") then clone.Position = position elseif clone:IsA("Tool") and parent and parent:IsA("Backpack") then -- Для предметов-инструментов clone.Parent = parent else -- Попытка найти PrimaryPart автоматически if clone:IsA("Model") then local primary = clone.PrimaryPart or clone:FindFirstChildWhichIsA("BasePart") if primary then clone:SetPrimaryPartCFrame(CFrame.new(position)) end end end return clone end
-- Примеры использования: -- Спавн мамонта spawnVisualObject("Animals", "Mammoth", Vector3.new(50, 5, 50)) -- Спавн робота-торговца spawnVisualObject("Animals", "RobotTrader", Vector3.new(100, 5, 100)) -- Спавн яркого сундука spawnVisualObject("Items", "ColorfulChest", Vector3.new(120, 2, 120)) -- Спавн машины spawnVisualObject("Vehicles", "Car", Vector3.new(200, 2, 200)) -- Спавн дерева spawnVisualObject("Nature", "SpringTree", Vector3.new(80, 2, 80))
-- Для выдачи предмета игроку (например, меча): -- spawnVisualObject("Items", "ClassicSword", nil, player.Backpack)
-- Для визуальных эффектов (пример): local function addParticleEffect(part, effectType) if not part or not part:IsA("BasePart") then return end local emitter = Instance.new("ParticleEmitter") if effectType == "magic" then emitter.Texture = "rbxassetid://284205403" -- пример текстуры emitter.Color = ColorSequence.new(Color3.new(1,0,1)) emitter.Rate = 20 emitter.Lifetime = NumberRange.new(1,2) elseif effectType == "snow" then emitter.Texture = "rbxassetid://6023426915" emitter.Color = ColorSequence.new(Color3.new(1,1,1)) emitter.Rate = 50 emitter.Lifetime = NumberRange.new(2,4) end emitter.Parent = part end
-- Пример: добавить магический эффект к сундуку local chest = spawnVisualObject("Items", "ColorfulChest", Vector3.new(130, 2, 130)) if chest and chest:IsA("Model") and chest.PrimaryPart then addParticleEffect(chest.PrimaryPart, "magic") end