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

Output error in server but not in Edit mode...Can someone help with this?

I am creating a MusicGui in a game. It functions perfectly fine when im in edit or build mode, However when you join an actual server it doesn't function at all. I pulled up the output in the server and i get the error message "Song is not a Valid Member of ScreenGui" but again I do not get this error in edit or build modes.

It is set up like this

Players
	PlayerName
		PlayerGui
			MusicGui
				Song
				Frame
					Play
						localscript
					Next
						localscript
					Stop
						localscript

It also says the error is in line 2 of Play, Next, and Stop's scripts when in the server.

This line is the same in all three scrips and it is:

Song = script.Parent.Parent.Parent.Song

If you need the whole scripts here they are

Play localscript

Player = game.Players.LocalPlayer
Song = script.Parent.Parent.Parent.Song
function PlaySong()
	Song:Play()
end

script.Parent.MouseButton1Down:connect(PlaySong)

Next localscript

Player = game.Players.LocalPlayer
Song = script.Parent.Parent.Parent.Song

function NextSong()
	if Song.SoundId == "http://www.roblox.com/asset/?id=143959455" then
		Song:Stop()
		Song.SoundId = "http://www.roblox.com/asset/?id=131111368"
	elseif Song.SoundId == "http://www.roblox.com/asset/?id=131111368" then
		Song:Stop()
		Song.SoundId = "http://www.roblox.com/asset/?id=142435409"
	elseif Song.SoundId == "http://www.roblox.com/asset/?id=142435409" then
		Song:Stop()
		Song.SoundId = "http://www.roblox.com/asset/?id=155179087" 
	elseif Song.SoundId == "http://www.roblox.com/asset/?id=155179087" then
		Song:Stop()
		Song.SoundId = "http://www.roblox.com/asset/?id=143959455"
		end
end

script.Parent.MouseButton1Down:connect(NextSong)

Stop localscript

Player = game.Players.LocalPlayer
Song = script.Parent.Parent.Parent.Song

function PlaySong()
	Song:Stop()
end

script.Parent.MouseButton1Down:connect(PlaySong)

and again this only happens in the server, in edit or build mode it works just find with no error messages! Thanks!

2 answers

Instead of Song = script.Parent.Parent.Parent.Song, do local Song = script.Parent.Parent.Parent:WaitForChild("Song")

This makes sure it exists before continuing, it also returns the item it ends up finding. It is the same as :FindFirstChild(name) but it waits until it is actually there.

The way Roblox loads items is unusual as sometimes scripts actually load before the items, so it is much safer to just wait for the item you need instead.

I'll take a look at it, and I'll see what I can do. I'll get back to ya.

2 comments

0

okay thanks

0

I am afraid I cannot figure it out, sorry.

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