lua
local sound = script.Parent
local trainPart = sound.Parent -- Деталь, к которой привязан звук
-- Проверяем, движется ли поезд
while true do
if trainPart.Velocity.Magnitude > 0.1 then
if not sound.IsPlaying then
sound:Play()
end
else
sound:Stop()
end
task.wait(0.1) -- Проверка каждые 0.1 секунды
end