Can compare “counter” in the (counter >= 1.5)
to a lower number like 0.1. That will make it go faster. You can adjust this to taste. Also, is it possible to do something like:
local counter = 0
local startsChildren = starts:GetChildren() -- set this up top
game:GetService (etc....)
-- then
local randomSpawn = startsChildren [math.random(1, #startsChildren)]
…so you aren’t calling GetChildren constantly inside that Heartbeat handler, or do the contents of “start” change all the time? There are other ways to do that if the contents of “start” need to change.
At any rate, that code (and the alternatives suggested by others above) will allow you to slow down the rate at which those parts are being created. Matching the beat is a separate problem. Currently, you’re following along with the loudness value of the soundtrack and creating parts when the sound is loud and not when it’s quieter. The result, visually, is something like this (where ‘o’ are parts and ‘_’ are no parts):
oooooooo_______oooooo______ooooooooo__ooooooooooooo
The song is moving forward in time and your code is sampling the loudness at a constant rate. Before we adjusted the code, it was sampling it very quickly and creating a lot of parts. By slowing it down to 1 sample every 1.5 seconds (what the if (counter >= 1.5) is doing), we’ve dramatically reduced the number of boxes being created, but they are still being created effectively the same way as before. They aren’t on the beat now because they weren’t on it before. Let me see if I can illustrate…
So, the overall pattern hasn’t changed. If you speed it up to 1 sample per 0.1 sec (as mentioned above) you’d get something more like pattern below, which would look more like what you were seeing earlier at full speed, but with fewer blocks.
o o o o o _ _ _ _ _ o o o o _ _ _ _o o o o o o _ o o o o o o o o o
Right now (at 1.5), the sample rate is too slow so it’s more like:
___o__________o ___________________o_________o
But the pattern is still essentially the same. The problem here is that you aren’t really tracking a beat. It’s just mapping swings in the volume. It does nothing until the loudness hits your threshold and then it draws a bunch of boxes until the loudness falls below the threshold again. That technique would probably work fine if there was nothing in the soundtrack but a beat, but that doesn’t sound like what you’re aiming for. That’s what I was referring to in my first post when I said, “I’m having a hard time visualizing how you get the kind of rhythm info needed for a game from just the loudness of the soundtrack…”. If you want the players to do something like headbang or jump around or strum instuments while the loudness is high and then stop when it’s lower, then you can probably dial the sample rate in to something that would be smooth without generating too many parts. If you need to have parts generated on the beat or on the notes, then I don’t know if that’s possible to automate with audio methods we have access to in Roblox. Anyway, try setting that 1.5 number to something else between 0 and 1 and see if you get a flow rate you’re happy with.
Edit: Searched around a bit and found these two threads. The first may help you with automating the process using the loudness. The second is an open source game that uses a diff technique. You may have seen these already, but figured I’d update the post just in case you hadn’t.
Best way to create rhythm for my rhythm game? - Help and Feedback / Scripting Support - DevForum | Roblox
[Open Source] RoBeats (Rhythm Game) Custom Server Template - Resources / Community Resources - DevForum | Roblox