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 PlaybackSpeed linear to Speed?

I want to make car sounds. You know, so as speed increases, playback speed increases.

2 comments

0

Normalize the car's speed (i.e. make it a value between 0 and 1, possibly by dividing it by the car's max speed) and set it as the sound's volume/speed.

0

Why did somebody down vote this? What the hell did I do wrong?

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

13 comments

0

What should I change it to

0

@TheBeaver101 the sound instance

0

Forgive me, but like... what exactly is a sound instance? I know you're laughing at me right now but I literally just started with studio and scripting.

0

@TheBeaver101 the thing that plays sound

0

Oh lol ok thanks. So if it's in a part then just put the part name.

0

@TheBeaver101 well it cant be a part instance because it needs to be a sound instance

0

So the sound instance is basically the thing called "Sound" you put in to a part, union, whatever. So if it was named "sound" I'd just put "sound" right?

0

@TheBeaver101 yea like script.Parent or workspace.Sound just get to sound

0

@DanzLua do I need to add anything to the vehicle seat that I am putting this script in besides the sound?

0

Does not work. On the 5th line "Sound" has a blue line under it. "W001 Unknown Global 'Sound'" it says.

0

@TheBeaver101 on line 5 change Sound to sound

0

It doesn't work :/ Is there something else I need to add to the vehicle seat? The name is Vehicle Seat for the seat, and I have nothing in there besides the script and the sound and some welds.

0

@TheBeaver101 If you don't understand what I'm saying I suggest you read up on basic scripting before you use this site

Perhaps have a value for the speed of the car, and the max speed of the car..

You can change the volume then using a Changed event on the carSpeed, and the formula: Volume = CarSpeed/MaxCarSpeed

local carSpeed = script.Parent:WaitForChild("carSpeed") --speed val
local maxSpeed = script.Parent:WaitForChild("maxSpeed") --maxspeed val
local volume = script.Parent:WaitForChild("Volume") --volume val

carSpeed.Changed:Connect(function(new) --Changed event on speed val
	volume.Value = new/maxSpeed.Value --formula
end)

4 comments

0

Wait... so what should the whole script look like? I'm starting out and I know nothing about scripting. Should I add some NumberValues too?

0

That's what the whole script should look like. vals should be actual IntValue/NumberValue objects, yes.

0

Should I have the Values in Configurations?

0

-_-

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