Hello !
I’m currently having some troubles with the sound playbackspeed when I throttle up and down the vehicle. Here is the script that should change the sound playbackspeed ;
ThrotSound = script.Parent.Engine
ThrotSound2 = script.Parent.Engine2
curSpeed = script.Parent.Parent.State.currentSpeed.Value
if curSpeed < 10 then
print("aaa")
ThrotSound.PlaybackSpeed = 0.9
ThrotSound2.PlaybackSpeed = 0.9
elseif curSpeed >= 10 and curSpeed < 20 then
print("aa")
ThrotSound.PlaybackSpeed = 1.5
ThrotSound2.PlaybackSpeed = 1.5
elseif curSpeed >= 20 then
print("bb")
ThrotSound.PlaybackSpeed = 1.1
ThrotSound2.PlaybackSpeed = 1.1
elseif curSpeed >= 30 then
print("cc")
ThrotSound.PlaybackSpeed = 1.2
ThrotSound2.PlaybackSpeed = 1.2
elseif curSpeed >= 40 then
ThrotSound.PlaybackSpeed = 1.3
ThrotSound2.PlaybackSpeed = 1.3
elseif curSpeed >= 60 then
ThrotSound.PlaybackSpeed = 1.4
ThrotSound2.PlaybackSpeed = 1.4
elseif curSpeed >= 70 then
ThrotSound.PlaybackSpeed = 1.5
ThrotSound2.PlaybackSpeed = 1.5
else
ThrotSound.PlaybackSpeed = 1.5
ThrotSound2.PlaybackSpeed = 1.5
end
The throttle perfectly works. The speed value changes everytime.
Some help could be REALLY appreciated. Thanks.
1 Like
riles0829
(riles)
November 14, 2020, 10:48pm
#2
elseif curSpeed >= 10 and curSpeed < 20 then
Try setting an upper bound for the other elseif statements as you did for this one.
Oh, I forgot to modify, but I already tried with the first elseif, and it still doesn’t work.
1 Like
riles0829
(riles)
November 15, 2020, 1:57am
#4
Are the if statements in loop? If not, the script will only run once and it won’t continuously check for a speed change.
I already tried in the past, but the loop returns an error ;
1 Like
riles0829
(riles)
November 15, 2020, 2:01am
#6
Add wait(0.1) to the end of the loop. This should fix the error.
1 Like
It fixes the error, but the script seems to understand only the first if.
while true do
if curSpeed >= 0 and curSpeed < 10 then
print("aaa")
ThrotSound.PlaybackSpeed = 0.9
ThrotSound2.PlaybackSpeed = 0.9
elseif curSpeed >= 10 and curSpeed < 20 then
print("aa")
ThrotSound.PlaybackSpeed = 1
ThrotSound2.PlaybackSpeed = 1
1 Like
riles0829
(riles)
November 15, 2020, 2:17am
#8
Did you throttle the vehicle at all during the test? It seems that the speed was only between 0 and 10 for the entire test.
Sure I did, I was going on a speedvalue = 35
So, with proofs ;
Its normal.
Not normal.
Because if you got the speed on the locomotive, it’s 40. I should have this ;
elseif curSpeed >= 40 and curSpeed < 60 then
ThrotSound.PlaybackSpeed = 1.3
ThrotSound2.PlaybackSpeed = 1.3
1 Like
riles0829
(riles)
November 15, 2020, 2:19am
#10
I think I figured it out. Try defining curSpeed within the while loop. That way, the variable is updating. Otherwise it would remain at the same value the entire time.
Yep ! It works, thanks ! The problem was with that thing not updating, now it does.
1 Like
riles0829
(riles)
November 15, 2020, 2:24am
#12
Awesome! I’m glad I could help.
1 Like