Hello! I’ve been trying to make an ocean generation system for quite a bit of time now, and I’ve run into an issue that I don’t know how to solve.
Basically, my script gets a chunk based on the camera position (game is first person), and checks if the camera is in a new chunk, and loads more water.
The problem is, sometimes this doesn’t work, as shown in the video (either delayed or just not happening at all)
From a quick glance, I see that you loop your code every 1 seconds :
while task.wait(1) do
I think you should either replace it with a task.wait() (check and see if the delay comes from here), or you can consider enlarging the chunks loaded (maybe generate 9 chunks around the player, the one he’s on, and the 8 adjacent). I might be missing something, but is your code already doing that, or is it generating only the chunk the player is on (on the grid) ?
The issue is you only actually load new chunks every second. If a check occurs right before a player enters a new chunk there will be a delay before your loop runs again. Also it is generally not a good practice to put task.wait() as a condition for while loops. It’s better to set the condition to true and to call task.wait() inside the loop itself. It might be a good idea to switch to using the .RenderStepped event from the RunService as that will guarantee new chunks are loaded in time. Alternatively you can also load multiple chunks around the player so your chunks will update before the player can exit the loaded area.
Try using Delta time to reload the sea every game’s frame, as per the other fellas are saying, it should be more smoother since it will not be scaled to the players FPS nor will it update every second, and regarding the issue with them not spawning at all try doing more test runs and see if any errors and prompting up in the output!
The issue you’re encountering might be due to the fact that your code waits for 1 second (task.wait(1) ) before checking the camera’s position again. During this time, the camera might move into a new chunk, but the script hasn’t detected it yet because it’s waiting.
Edit: You could replace the 1-second wait loop with a RenderStepped event listener to continuously update the ocean based on the camera’s position changes for real-time responsiveness.