OOP Sound Events Module

Hi, have you ever had the issue of timing things in roblox studio according to a sound, but just never felt like manually writing out repeat untils or waiting until the sound reaches a timePosition?

I’ve created a solution in about 30 minutes at 2 AM: Sound Events

Functions

SoundEvent.new(): Creates a new SoundEvent object, and requires the parameters in this order:
soundInstance: Sound, timePosition: number, amount: number, fExec: (any) → (any)

Heres a code snippet of me making basic functionality:

local SoundEvents = require(game.ServerScriptService.SoundEvents)
local Sound = workspace.WhateverSoundIdk

local SoundEvent1 = SoundEvents.new(Sound, 5, 1, function(EventData: SoundEvents.soundEvent?)
	print("I play at the 5 second mark!")
	print(`({string.format("%.2f", math.abs(5-EventData.soundInstance.TimePosition))}s difference)`)
end)

There are two more functions, however they are very obvious as to what they do, but I’ll just list them here.

SoundEvent:Disable()
SoundEvent:Enable()

The module also exports a type for all soundEvents, such as used in the code snippet.
The module also checks for sound events every 1/20th of a second for optimization (instead of using heartbeat or something like that) and also for precision.

I feel the need to state this is my first time making a public use module, and making a post like this.

I’d appreciate feedback on how I could make this better.
Thank you

The Module

2 Likes

Why use this over something like task.delay?
Am I misinterpreting the use case?

has amounts and is just generally easier to read i guess. I dont know lol I made it at 2 AM.
I am aware such things like PropertyChangedSignal exist however this is mostly readability and works based off TimePosition so it is also accurate even if the playback speed is lower or higher.

Im pretty sure its too small to be posted here.

My bad, should I take it down?

i believe its a pretty cool resource that shouldnt be taken down, could the code be improved? sure and i wouldnt mind talking about it in dms. stuff like this could be useful for special important moments marked on a song, like a drop with special effects or marking scenery changes, i guess it could be an equivalent of keyframereached in animations but in sounds.

I’d love to know what I could change about it, unfortunately i dont know how to access dms lol