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
try this if this helps make sure you accept this as your answer
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 if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then Found = true break else Found = false end end if Found == true then 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
I found out how. All I had to do was put the audio folder and LocalScript into a ScreenGui in StarterGui and turn the ResetOnSpawn property in the ScreenGui to False.
I hope this helps people!