Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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
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) Mayk728 855 — 4y
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 danger1111190 0 — 4y
0
also how do i do that and what do i have to change danger1111190 0 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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
0
Sorry it did not work danger1111190 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

0
it wont let me accept this as my answer lol danger1111190 0 — 3y

Answer this question