#Help tweak an audio script

1 messages · Page 1 of 1 (latest)

full acorn
#

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```
full acorn
#

Help tweak an audio script

abstract tinsel
#

instead of using resume and pause

#

every sound has a volume property

#

use volume = 0 and volume = 1 (or more if you want it that way)

#

@full acorn

full acorn
#

unless I'm doing it wrong

#

I now have

abstract tinsel
#

can I see the explorer

full acorn
#

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]:Volume = 0.125()
    break
   end
  else
   script.Parent.SoundRegions[v.Name]:Volume = 0()
  end
 end
end```
abstract tinsel
#

where you have the sounds?

abstract tinsel
#

on volume

#

it is only one dot

#

not two

#

: is for calling functions

#

since this is a property then just one dot

full acorn
#

ok

abstract tinsel
#

and after 0 and 0.125 there is no need to place a ()

#

that is also for functions

#

this is just a float

#

script.Parent.SoundRegions[v.Name].Volume = 0

full acorn
abstract tinsel
#

yup

#

try what I just said

#

and tell me how it goes

full acorn
#

huh

#

wait no nvm

#

ok it still doesn't seem to be working

#

The code now is

#

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].Volume = 0.125
    break
   end
  else
   script.Parent.SoundRegions[v.Name].Volume = 0
  end
 end
end```
#

I have them both on playing and at volume 0

abstract tinsel
#

ok so

#

which is the problem now

#

they do not muter

#

mute?

#

or they do not unmute

full acorn
#

they do not unmute

#

cuz I have them set to mute by default

abstract tinsel
#

do you mute them on explorer

#

or do you mute them on a script

full acorn
#

explorer

abstract tinsel
#

aight

#

so on the explorer you got volume = 0

full acorn
#

yes

zealous escarpBOT
#

studio** You are now Level 1! **studio

abstract tinsel
#

I meant

#

not that one

#

the one you had at the start

full acorn
#

yes the first one worked

abstract tinsel
#

I see the problem

#

so, on the if part you got someting that says .IsPlaying == false

#

this checks if the audio is NOT playing

#

and if it is not playing then it does the thing

full acorn
#

ah I see

abstract tinsel
#

since we deleted the :Stop() line

#

then it is always playing so that part never executes

#

delete the .IsPlaying part

full acorn
#

Ok it seems to work now!

#

I changed it to if volume == 0

abstract tinsel
#

alright

full acorn
#

or is that redundant?

abstract tinsel
#

It is never bad to have an extra check

#

so I'd leave it like that

full acorn
#

ok

#

thank you very much!

#

This has been annoying me for years lol

#

great to see it working as I wished

abstract tinsel
#

Alright