Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does sound "Idle" continue playing?

Asked by 9 years ago

All of the (name)=script.parent.(name) are Audios that are in a VehicleSeat with the script that contains this code. Ideally, when you touch the seat, the Start noise will play, and then if the current speed of the car is under .1 studs per second, the Idle noise will play on loop. If the car is above .1 studs per second(moving) than the Low audio will play on loop, and the Idle noise will stop....

The start sound works fine, then the Idle sound plays directly after the start sound stop, but it never stops after that point....

Gear=script.Parent.Gear
Start=script.Parent.EngineStart
Max=script.Parent.MaxEngine
High=script.Parent.HighEngine
Med=script.Parent.MediumEngine
Low=script.Parent.LowEngine
Idle=script.Parent.IdleEngine


function onTouched(hit) 
Start:Play()
wait(2.586) --Time of start noise.
Idle:Stop()
Idle.Looped = false
Low:Stop()
Low.Looped = false
if
script.Parent.Velocity.Magnitude<= .1
then Idle.Looped = true
Idle:Play()
Start:Stop()
Low:Stop()
Low.Looped = false
elseif
script.Parent.Velocity.Magnitude>= .1
then Idle.Looped = false
Idle:Stop()
Start:Stop()
Low:Play()
Low.Looped = true
end
end
script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
-1
Answered by
Kryddan 261 Moderation Voter
9 years ago

I haven't test this but try to add a

while wait() do

right before the if statement at line 17

and end it under the "end" at line 31

i think the problem is that you only check once if the speed is less then .1 or more then .1

Final code:

Gear=script.Parent.Gear
Start=script.Parent.EngineStart
Max=script.Parent.MaxEngine
High=script.Parent.HighEngine
Med=script.Parent.MediumEngine
Low=script.Parent.LowEngine
Idle=script.Parent.IdleEngine


function onTouched(hit) 
Start:Play()
wait(2.586) --Time of start noise.
Idle:Stop()
Idle.Looped = false
Low:Stop()
Low.Looped = false
while wait() do
if
script.Parent.Velocity.Magnitude<= .1
then Idle.Looped = true
Idle:Play()
Start:Stop()
Low:Stop()
Low.Looped = false
elseif
script.Parent.Velocity.Magnitude>= .1
then Idle.Looped = false
Idle:Stop()
Start:Stop()
Low:Play()
Low.Looped = true
end
end 
end
script.Parent.Touched:connect(onTouched)

0
The answer to everything is not an infinite loop........ NotsoPenguin 705 — 9y
Ad

Answer this question