Introducing SoundStepEvents
Much like the roblox animator which has custom keyframe events, I wanted to implement something like it for roblox sounds, now this is a useful module for many things such as play orientated features which are activated depending on the time position of a sound.
While there isnt an official remedy for doing this, this module can mimic that in a sort of way.
There are known limitations with this module, such as, you cannot use decimal numbers such as 5.2
as the script floors the time position to find an entire number.
Now, I whipped this up in a few minutes as I needed it for one of my own games, but feel free to use it, I made some speedy documentation to get you started.
If there are bugs, I’ll not be fixing it as this is just a quick module to give developers a quick remedy to this annoying lack in feature.
local SoundStepEvents = require(location.to.class)
local Stepper = SoundStepEvents.new({
Sound = workspace["Sound"], -- The sound you wish to bind to.
Events = {
[5] = "This event fires when time position floors itself to 5 seconds!",
[10] = "This event fires when time position floors itself to 10 seconds!"
--Format is [timeposition in whole number] = "event name"
},
Misc = {
RunOnce = false; --Destroy instance once the sound finishes.
}
})
Stepper.EventStepped:Connect(function(EventName: string) --Connect an event to listen for when the listed events are fired.
print(EventName) --Collect the event.
end)
Stepper:GetStepsReached() --If not destroyed and sound is playing, collect all markers reached.
Stepper:Destroy() --Destroy resource usage.
Once you connect your sound instance to the stepper module, it will automatically start/stop when you use :Play()
or :Stop()
on your sound instance.
Get it here