Use ZonePlus instead of a while loop to check for the player being inside or outside:
This is a recommendation.
Now, if you absolutely want to stick with your method, then that’s fine too.
The reason why your sound isn’t ending immediately is due to the fact that you have too many waits.
What I propose we do instead is we scrap the usage of a while loop, and instead use “:GetAttributeChangedSignal()”.
This way, we won’t have any delays with our script.
Here’s how we implement this:
local plr = game.Players.LocalPlayer
local Character = plr.Character or plr.CharacterAdded:Wait()
local MusicsFolder = workspace.Musics
local Music = 0
local Song = nil
local CurrentNumber = 0
Character:GetAttributeChangedSignal("Location"):Connect(function()
local location = Character:GetAttribute("Location");
if location == "Outside" then
Song:Stop()
Music = Music + 1
CurrentNumber = Music
if Music > 10 then
Music = 1
end
if Music == 1 then
Song = MusicsFolder.song01
end
Song = MusicsFolder["song0"..Music]
Song.TimeLength = 0;
Song:Play();
elseif location == "InAngelShare" then
Song:Stop()
Song = MusicsFolder.AngelShare
MusicsFolder.AngelShare:Play()
end
end)
Let me know if this helped.