It’s meant to generate two seperate models and it switches everytime it moves forward a tile on the x-axis but it doesnt work. Anyone know why?
Script:
-- Services --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
-- Ocean Templates Folder --
local oceanFolder = ReplicatedStorage:WaitForChild("OceanTemplates")
-- Starter Part --
local starterPart = Workspace:WaitForChild("StarterPart")
-- Configuration --
local sizeX = 24
local sizeZ = 24
local oceanHeight = starterPart.Position.Y
local loadedPositions = {}
local toggle = true
-- Generate Ocean Model --
local function generateOceanModel(x, z)
-- Alternate between Ocean1_1 and Ocean2_1
local oceanModel = (toggle and oceanFolder:WaitForChild("Ocean1_1")) or oceanFolder:WaitForChild("Ocean2_1")
toggle = not toggle
-- Create the ocean model
local position = Vector3.new(x * sizeX, oceanHeight, z * sizeZ)
local oceanPart = oceanModel:Clone()
oceanPart:SetPrimaryPartCFrame(CFrame.new(position))
oceanPart:PivotTo(CFrame.new(position))
oceanPart.Parent = Workspace
end
-- Generate Ocean Grid --
local function generateOceanGrid()
for z = -100, 100 do
for x = -100, 100 do
local key = tostring(x) .. "_" .. tostring(z)
-- Check if this position has already been generated
if not loadedPositions[key] then
generateOceanModel(x, z)
loadedPositions[key] = true
end
end
end
end
-- Start Generating Ocean --
generateOceanGrid()
StarterPart is in the workspace and the script is in StarterPart
-- Services --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
-- Ocean Templates Folder --
local oceanFolder = ReplicatedStorage:WaitForChild("OceanTemplates")
-- Starter Part --
local starterPart = Workspace:WaitForChild("StarterPart")
-- Configuration --
local sizeX = 24
local sizeZ = 24
local oceanHeight = starterPart.Position.Y
local loadedPositions = {}
local toggle = true
-- Generate Ocean Model --
local function generateOceanModel(x, z)
-- Alternate between Ocean1_1 and Ocean2_1
local oceanModel = (toggle and oceanFolder:WaitForChild("Ocean1_1")) or oceanFolder:WaitForChild("Ocean2_1")
toggle = not toggle
-- Create the ocean model
local position = Vector3.new(x * sizeX, oceanHeight, z * sizeZ)
local oceanPart = oceanModel:Clone()
oceanPart:PivotTo(CFrame.new(position))
oceanPart.Parent = Workspace
end
-- Generate Ocean Grid --
local function generateOceanGrid()
for z = -100, 100 do
for x = -100, 100 do
local key = tostring(x) .. "_" .. tostring(z)
-- Check if this position has already been generated
if not loadedPositions[key] then
generateOceanModel(x, z)
loadedPositions[key] = true
end
end
end
end
-- Start Generating Ocean --
generateOceanGrid()