Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not A Valid Member of Any Parent?

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

✓ Accepted answer

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.

2 comments

0

Yes! It worked, thank you. I appreciate the help from all of you.

0

No problem, glad I could help :D

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

4 comments

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.

0

Try game.Players.LocalPlayer.PlayerGui.ScreenGui.Sound

0

Worked again in Studio. Not in the game! e.e

0

Wtf ;-;

This discussion is preserved as it was. New answers, comments, and votes are closed.