so, I want to disable a sound file after it has ended, the way I’m doing it is transferring the sound file to another folder once it ends. But then it just gives errors when the script cant find the sound file, so I want to know if there’s a better way to do this other than using debounce as it will also affect all the other sound files that will be playing after.
this is the main LocalScript
local Player = game:GetService("Players")
local SoundService = game:GetService("SoundService")
local Subtitle = Player.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Subtitles"):WaitForChild("Subtitle")
local SoundFolder = game.Workspace.Narration
local DisabledAudio = game.Workspace.Narration.DisabledAudio
local Remotes = game.ReplicatedStorage.Remotes
--//Intro Narration
Remotes.Intro.VoiceIntro1.OnClientEvent:Connect(function(plr)
local VoiceIntro1 = SoundFolder.Intro.voice_intro_1_00
VoiceIntro1:Play()
Subtitle.Text = "Text"
if VoiceIntro1.Ended:Wait() then
VoiceIntro1.Parent = DisabledAudio
end
end)
.Ended is an Event, I don’t know why you’re trying to sanity check it through an if statement
Since you’re calling it with a Wait() function, all you just need to do is remove the conditional check and replace it with this as the function will yield until the specified action has been completed:
If you want to keep using your method of reparenting you could do a check to see if it still exists by adding an if. This should fix your “But then it just gives errors when the script cant find the sound file” error.
Remotes.Intro.VoiceIntro1.OnClientEvent:Connect(function(plr)
local VoiceIntro1 = SoundFolder.Intro:FindFirstChild("voice_intro_1_00")
if VoiceIntro1 then
VoiceIntro1:Play()
Subtitle.Text = "Text"
VoiceIntro1.Ended:Wait()
VoiceIntro1.Parent = DisabledAudio
end
end)