I GOT IT WORKING YAY. thanks very much. But one follow up question. Is there a way to make it skip even more heartbeats? And if so, will that help reduce even more lag? In my project i don’t need the sound to happen instantaneously on the button as soon as you leave the region.
local POLL_THRESHOLD = 10
local regionIndex = 0
local pollCount = 0
game:GetService( 'RunService' ).Heartbeat:Connect( function ()
pollCount = pollCount + 1
if pollCount < POLL_THRESHOLD then
return
end
pollCount = 0
regionIndex = regionIndex % #SoundRegions + 1
-- rest of code here
Essentially waits for a specified number of heartbeats before incrementing and doing the next region. In this case, 10, which is roughly 1/6th of a second break on the client. Increase the number to make it take longer. 60 will be roughly 1 second pause between each region check.
Feel free to mark any of my replies (ideally the one you think other people will find most helpful) as the solution to indicate your problem has been solved. Glad to have been able to help