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