i got a script that plays a sound in different regions, but i dont understand where the error is. when ever i enter a region the music plays, but whenever i leave or go into another one the music continues to play and another begins.
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 through the parts table
if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
--print("Player was found")
Found = true
break
else
Found = false
--pring("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

2 comments
^ sorry about the way its presented
Stolen from https://www.youtube.com/watch?v=L_Jga2MgRdU