Hey so I’m having an issue with this sounds region script, sometimes it just stops after playing a few difficulties of my game and occasionally I have to rejoin for the music to start playing again. I’m not too sure what the repro steps are but if someone could analyze this script and see why this might be happening. The sound region parts aren’t touching each other nor far apart that it stops. I’ve seen this occur when I enter different difficulties and it happens 30% of the time but of course I want this to happen 0% of the time. Remember it happens when I enter a new difficulty because that’s when new music starts playing.
Script:
local SoundRegionsWorkspace = game.Workspace:WaitForChild("SoundRegions")
local SoundTable = {}
for i, v in pairs(SoundRegionsWorkspace:GetChildren()) do
table.insert(SoundTable, game.Workspace.SoundRegions2[v.Name].Volume)
wait(0.2)
end
local Found = false
while wait(.5) do
for i, v in pairs(SoundRegionsWorkspace:GetChildren()) do
local sound = game.Workspace.SoundRegions2[v.Name]
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
print("Player Was Found")
Found = true
break
else
Found = false
print("Player Not Found")
end
end
if Found == true and sound.IsPlaying == false then
wait(0.1)
sound:Play()
for i = 0, SoundTable[i], 0.05 do
sound.Volume = i
wait(0.1)
print"Sound Faded In"
if sound.Volume == SoundTable[i] then
print("Sound Faded In")
break
end
end
end
if Found == false and sound.IsPlaying == true then
wait(0.1)
print("Waited")
for i = SoundTable[i], 0, -0.05 do
print("Fading Out")
sound.Volume = i
wait(0.1)
end
sound:Stop()
end
end
end