Help, PasteRegion() timeout!

Hi everyone,
I’m having a problem with in-built PasteRegion() function. I use it to load a smooth terrain for the next round. The issue is when it’s about to load the entire main script just crahes, very frequently, almost 30% of the time. It happens due to a script timeout. It seems that PasteRegion() takes too much time to execute.

terrain:PasteRegion(curMapPath.SavedTerrain, Vector3int16.new(-32000, -32000, -32000), false)

error message:

Script timeout: exhausted allowed execution time

What I want to achieve? I’d love any help to figure out a way to possibly disable / lengthen default timeout time or tell the script to yield when the function is happening or how can I deal with that differently? Unfortunately I can’t edit the PasteRegion() itself.

I’ve tried putting it into coroutine, spawn, pcall. I’ve tried adding wait(10) before and after the function, and also I’ve tried retrying the function when it gets timed out, but the thread is getting killed even in pcall()

I appreciate any help, it’s urgent.

1 Like

I have no experience using the terrain API, but judging by what the error message says, you’re trying to paste too much terrain all at once. The way to fix this is to probably copy and paste chunks of the terrain instead of the whole terrain itself.

Yeah, it would work, but I have to put a lot of work to make it work properly, everytime when I change something in the terrain, I’d need to seperate to chuncks again. Also I don’t know how small should the chunks be, timeout happens sometimes on bigger maps, the other time on smaller.