If I set the while function to "while wait(1)" the code stops working but if I set it to "while wait()" then it works temporarily while the game is loading and then stops working. There are no errors in the output from that script.
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
print("for")
if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
print("Player was found")
Found = true
break
else
Found = false
print("Player was not found")
end
end
if Found then
if game.Workspace.Sound[v.Name].IsPlaying == false then
print("music")
game.Workspace.Sound[v.Name]:Play()
break
end
else
game.Workspace.Sound[v.Name]:Stop()
end
end
end

1 comment
Not an answer, but because parts is the descendents of the player, you don't need to do the for _, part in pairs(parts) do, you can instead do local Found = #parts > 0