Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make it so that as the speed of a car increases, the pitch of a sound increases?

I want to make it so that as the speed of a car increases, the pitch of a sound that is in the vehicle seat also increases. Here is the current function that I have:

local maxSpeed = filtered local minPitch = filtered local maxPitch = filtered local pInc = (maxPitch / maxSpeed)

local function setPitch(speed) local currPitch = (speed * pInc) currPitch = math.clamp(currPitch, minPitch, maxPitch) sound.PlaybackSpeed = currentPitch end

What do I need to do to make it work? I have it in my vehicle seat with a sound that is not playing. Please help, I have been looking for months.

3 comments

0

Pitch is deprecated, but you can achieve a similar effect by inserting a PitchShiftSoundEffect into the Sound Object

0

but

0

The point is to make it so as you accelerate the sound playing in the vehicle seat gets a higher pitch, or in this case now, higher playback speed. So speed is linear to playback speed basically is what I want, similar to the cars in jailbreak or prison life.

2 answers

We are going to change the pitch of our sound change depending on the velocity of the Seat

We will create a while loop that will take the velocity of the seat and get a speed out of it, then we will do some math to get the pitch we want to set the sound to

local seat = script.Parent.MainSeat
local sound = script.Parent --Change this
while true do
	speed = math.floor(math.sqrt((seat.Velocity.X^2)+(seat.Velocity.Y^2)+(seat.Velocity.Z^2)))
	Sound.Pitch = (speed/150)+1
	wait(.5)
end

7 comments

0

What should I put for the second line?

0

It does not work :C

0

@TheBeaver101 the sound ;-;

0

Wait so the id?

0

@TheBeaver101 no the sound instance ;-;

0

wait so what should it loo like

0

change the Sound.Pitch to Sound.PlaybackSpeed

This discussion is preserved as it was. New answers, comments, and votes are closed.