I currently have this code here. It works to pause a sound when a player is inside a part and pause it once it leaves the area. I am not much of a coder, but how would I change this so instead of pausing and playing, it mutes the sound when the player is not in the part and plays it when the player is in the part?
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 not 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]:Resume()
break
end
else
script.Parent.SoundRegions[v.Name]:Pause()
end
end
end```
** You are now Level 1! **