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.
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.
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