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

Not A Valid Member of Any Parent?

Asked by 8 years ago
Edited 8 years ago

No matter where I put a 'Sound' named 'Sound' in the 'ScreenGui' named 'ScreenGui', the developer console gives the same error telling me 'Sound' is not a valid member of whatever it's parent may be. Whether it is the folder named 'Volume', or the 'ScreenGui' itself. The script works like a charm in testing mode in Studio. However, when I test the game while monitoring the local scripts via developer console, I am told 'Sound' is not a valid member of whatever it's parent is. Perhaps I am doing something completely silly and I am blind to it, but I would love to see what help anyone can provide. Thanks.

 -StarterGui
    -ScreenGui
        -Sound (Sound)
        -Choose (Frame)
        -ScrollingFrameHR
        -ScrollingFrameLR
        -ScrollingFrameMR
        -Apply (TextButton)
        -TextBox
        -TextLabel
        -TextLabel2
        -Volume (Folder)
            -High (ImageButton)
                -LocalScript
            -Low (ImageButton)
                -LocalScript
            -Mute(ImageButton)
                -LocalScript
        -Anim (Folder)

Below is one of the three local scripts that receive the error. They both use the same reference for audio. These work fine in Studio, not the game itself.

local Button = script.Parent
local audio = script.Parent.Parent.Parent.Sound --tried game.StarterGui.ScreenGui.Sound
local low = script.Parent.Parent.Low

function onClick()
    audio.Volume = 0.3
    low.Visible = true
    Button.Visible = false
end

Button.MouseButton1Click:connect(onClick)

Again, I don't know if I am just being absolutely silly and blind, but I got so frustrated.

2 answers

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

It could be the sound hasn't loaded when you've clicked your button so that's why the parent wouldn't be valid.

You can fix this by using WaitForChild().

So your code would be as follows:

local Button = script.Parent
local audio = script.Parent.Parent.Parent:WaitForChild("Sound") --tried game.StarterGui.ScreenGui.Sound
local low = script.Parent.Parent.Low

function onClick()
    audio.Volume = 0.3
    low.Visible = true
    Button.Visible = false
end

Button.MouseButton1Click:connect(onClick)

This might not be the problem, however usually when something works in studio but not in an actual game environment this is the problem.

0
Yes! It worked, thank you. I appreciate the help from all of you. Brisingr360 45 — 8y
0
No problem, glad I could help :D Rand0m3r 45 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Well assuming the script is located in "Apply" the text button then you are using too many parents. Try using script.Parent.Parent.Sound and let me know whether the error still occurs

0
Oh, I am so sorry I put ImageButton as a localscript, that should be an ImageButton with a localscript inside of that. Let me change that, sorry. Brisingr360 45 — 8y
0
Try game.Players.LocalPlayer.PlayerGui.ScreenGui.Sound tacktic2010 70 — 8y
0
Worked again in Studio. Not in the game! e.e Brisingr360 45 — 8y
0
Wtf ;-; tacktic2010 70 — 8y

Answer this question