Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Every time a player dies the music restarts, how do i stop this?

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

0

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)

0

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

0

also how do i do that and what do i have to change

2 answers

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

1 comment

0

Sorry it did not work

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!

1 comment

0

it wont let me accept this as my answer lol

This discussion is preserved as it was. New answers, comments, and votes are closed.