I want to change the SoundService's AmbientReverb property to NoReverb when it was previously Hallway, and Hallway when it was previously reverb. This script works if you remove the else if and just write "else Sound.AmbientReverb = "Hallway"" so it seems as though the if statement never evaluates to true. Can anyone help here?
function onTouch(part) local player = game.Players:GetPlayerFromCharacter(part.Parent) if player then local human = part.Parent:findFirstChild("Humanoid") if human then Sound = game:GetService("SoundService") if Sound.AmbientReverb == "Hallway" then Sound.AmbientReverb = "NoReverb" elseif Sound.AmbientReverb == "NoReverb" then Sound.AmbientReverb = "Hallway" end end end end script.Parent.Touched:connect(onTouch)
The if statement fails because Enums (like AmbientReverb) are actually integers, not strings. Setting an Enum using a string is possible, but the reverse isn't true.
Change your if statement to this:
if Sound.AmbientReverb == Enum.ReverbType.Hallway then Sound.AmbientReverb = "NoReverb" elseif Sound.AmbientReverb == Enum.ReverbType.NoReverb" then Sound.AmbientReverb = "Hallway" end
Also, you can save a little bit of lag by defining Sound
outside of the function.