Alternative Activation for Region3 other than a loop?

Okay, it’ll still work, you just need to add in the format shown in my snippet, so:

table.insert( SoundRegions, { region3, soundType } )

I noticed you didn’t have sound type in that last snippet, so you probably want to assign that where I’ve put the variable.

The loop will essentially update itself and start considering the new regions without having to touch the heartbeat function at all.

Yeah that snippet i just sent comes before the loop, it just finds all the markers and creates the regions, and puts the regions in the table

I GOT IT WORKING :smile: 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.

I would like to if i can keep the average pings as low as possible.

You could make it poll.

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.

1 Like

You get to be permanently instated as my personal hero! You have been so helpful thankyou so much!

1 Like

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 :slightly_smiling_face: