Car audio limiter

  1. What do you want to achieve? Keep it simple and clear!
    All I need is a piece of code to add for limiting the audio preventing it from sounding like the audio is going into infinity.
local function MainEngFunction1()
	MainEng1.Playing = true
	MainEng1.Volume = 0.2 + script.Parent.Velocity.Magnitude/150
	MainEng1.PlaybackSpeed = 0.175 + script.Parent.Velocity.Magnitude/125--the above code here works
	if script.Parent.Velocity.Magnitude < 50 then--The part below doesn't work and need a replacement.
		MainEng1.Volume = script.Parent.Velocity.Magnitude < 200
		MainEng1.PlaybackSpeed = script.Parent.Velocity.Magnitude < 200
	end
end

Add this after the volume is set, I guess.

local MaxVolume = 1
MainEng1.Volume = math.min(MaxVolume,MainEng1.Volume)

The code didn’t seem to work with no errors as I want to limit the cars acceleration sound/audio from going into infinity.

You are setting it to a boolean, there’s a lot of ways to do this.

local velocity = script.Parent.AssemblyLinearVelocity.Magnitude
-- dont use .Velocity, it's deprecated

MainEng1.PlaybackSpeed = (if velocity > 200 then 200 else velocity)
MainEng1.PlaybackSpeed = math.clamp(velocity,0,200)
MainEng1.PlaybackSpeed = math.min(velocity,200) -- like what @MasterStudioWorld said, it's also probably the best one

The code I tried didn’t seem to work, so I gave it the green checkmark anyways even tho it never worked since I found a different way of doing it. Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.