Pretty much I just want it to cycle through 6 different models over and over to make it look like an animated ocean. As you can see I attempted to do this but it doesn’t work. Any ideas?
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 frameDuration = 0.25
-- Generate Ocean Model --
local function generateOceanModel(x, z)
local position = Vector3.new(x * sizeX, oceanHeight, z * sizeZ)
local oceanPart = oceanFolder:WaitForChild("Ocean1_1"):Clone()
oceanPart:PivotTo(CFrame.new(position))
oceanPart.Parent = Workspace
task.spawn(function()
local frame = 1
while true do
local oceanModelName = "Ocean1_" .. frame
local nextModel = oceanFolder:WaitForChild(oceanModelName)
if nextModel then
local newPart = nextModel:Clone()
newPart:PivotTo(oceanPart.CFrame)
newPart.Parent = oceanPart.Parent
oceanPart:Destroy()
oceanPart = newPart
end
task.wait(frameDuration)
frame = (frame % 6) + 1 -- Loop through Ocean1_1 to Ocean1_6
end
end)
end
-- Generate Ocean Grid --
local function generateOceanGrid()
for z = -100, 100 do
for x = -100, 100 do
local key = tostring(x) .. "_" .. tostring(z)
if not loadedPositions[key] then
generateOceanModel(x, z)
loadedPositions[key] = true
end
end
end
end
-- Start Generating Ocean --
generateOceanGrid()
The starterPart is in workspace and the script is in that starterPart.