Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rng = Random.new()
- local function RandomInRange(range: number)
- return rng:NextNumber(-range / 2, range / 2)
- end
- local function GetNumber(inst: Instance, name: string)
- local total: number = 0
- while inst do
- total += inst:GetAttribute(name) or 0
- inst = inst.Parent
- end
- return total
- end
- local module = {
- ["MakeOneshot"] = function(sound: Sound) -- pass in a prototype sound to be cloned
- local pitchJitter : number = GetNumber(sound, "PitchJitter")
- local volumeJitter : number = GetNumber(sound, "VolumeJitter")
- local clone = sound:Clone()
- clone.Ended:Connect(function() clone:Destroy() end)
- clone.Looped = false
- clone.PlaybackSpeed = sound.PlaybackSpeed + RandomInRange(pitchJitter)
- clone.Volume = sound.Volume + RandomInRange(volumeJitter)
- clone.Parent = workspace
- return clone
- end
- }
- return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement