Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why won't AmbientReverb change?

Asked by 9 years ago

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)

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

0
Spotted a quotation mark left out from the previous script's string on line 3. Also, shouldn't line 2 and 4 have "Enum.ReverbType." too, instead of a string? Spongocardo 1991 — 9y
0
This worked fine, thanks! MasterDaniel 320 — 9y
1
Spongocardo: (You're right about the quote) When you are *setting*, most of the Enum values let you set friendly values, and it does the conversion for you. *Comparing* is where you need to be exact. BlueTaslem 18071 — 9y
0
@BlueTaslem Well, I learn something new everyday. Thanks again. Spongocardo 1991 — 9y
Ad

Answer this question