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

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

Asked by 9 years ago

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

Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
9 years ago

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.

Ad
Log in to vote
-2
Answered by 9 years ago

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

0
okay thanks austin10111213 28 — 9y
0
I am afraid I cannot figure it out, sorry. MatutinaStella 0 — 9y

Answer this question