PlayBackSpeed Changes with Speed

Hello, I’m trying to make a script that changes the PlayBackSpeed of a sound relative to the speed at which my vehicle is travelling.
I’m new to scripting, so I took an outdated script from a 2013 tutorial and tweaked it up a little.
When I was finished, the script looked like this:

local Seat = script.Parent
local Speed = math.floor(math.sqrt((Seat.Velocity.x^2)+(Seat.Velocity.y^2)+(Seat.Velocity.z^2)))

while true do

script.Parent.Sound.PlaybackSpeed = (Speed/10)+0.125

end

When I drive around with this script active, the sound doesn’t play, and with previous versions where it did, the pitch didn’t change at all. I’m not sure what I’m doing wrong here.

1 Like

Try using: local Speed = Seat.Velocity.magnitude
May have to adjust by adding and subtracting.

Or you can tweak the adjustment at (Speed/10)+0.125
(But make sure you have a value that adds if you want the sound to continuously run when at speed 0)

Forgive me I don’t have much experience with sound. But I would play with the math a little more.

1 Like

You aren’t updating the speed variable. You should also add a wait() into the loop.
I also don’t know how well this will work for like a car engine sound.

local Seat = script.Parent
local Speed;

while true do
    speed = Seat.Velocity.Magnitude
    script.Parent.Sound.PlaybackSpeed = (Speed/10)+0.125
    wait()
end
2 Likes

You aren’t updated “Speed” in your script and maybe instead of a loop use a event.

local Seat = script.Parent

Seat:GetPropertyChangedSignal('Velocity'):Connect(function()
    local Speed = math.floor(math.sqrt((Seat.Velocity.X ^ 2) + (Seat.Velocity.Y ^ 2) + (Seat.Velocity.Z ^ 2)))
    script.Parent.Sound.PlaybackSpeed = (Speed/10)+0.125
end)
2 Likes

Are you sure the Playing value is set to true; and that the sound is being :Play()'d from any script?

Continuing; you do also need to put the speed value within the actual loop; not outside or it won’t update.

1 Like

Thank you for your help, the s in speed wasn’t capitalised but that was a quick fix, I owe you one.

1 Like

Hey buddy is it possible for you to make a whole new driving system for my car other than using the A-Chassis Tuner?