My game is an obby so each stage has different music, but the music for each stage restarts when I die. I stored the LocalScript and the music in StarterGui, and the area blocks in a folder in Workspace
LocalScript:
local SoundRegionsWorkspace = game.Workspace:WaitForChild("SoundRegions")
local Found = false
while wait(1) do
for i, v in pairs(SoundRegionsWorkspace:GetChildren()) do
Found = false
local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, part in pairs(parts) do
--Loop one by one thrugh the parts table
if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
print("Player was found")
Found = true
break
else
Found = false
print("Player was not found in region")
end
end
if Found == true then
--Start playing some music
if script.Parent.SoundRegions[v.Name].IsPlaying == false then
script.Parent.SoundRegions[v.Name]:Play()
break
end
else
script.Parent.SoundRegions[v.Name]:Stop()
end
end
end

3 comments
well, it makes sense because everything in PlayerGui resets after respawning. you could try playing a sound in Workspace through the LocalScript (this would only play for you, but wouldn't restart after respawning)
The folder that contains the audios in StarterGui is named SoundRegions which is also the name for the folder for the area blocks in workspace. Does this effect anything
also how do i do that and what do i have to change