You could remove the variable check, for example if you stop moving but you set sound=off before this then it will not stop the audio. Sound can change between on/off very fast in one tick so you won't notice the change. If you can't work it out then try sharing the file.