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

Script doesn't work in online mode, only studio mode?

Asked by 9 years ago

My music player won't work when I actually play the game, the GUI doesn't appear and the music doesn't play, but yet when playing solo in studio mode, everything works fine. Why is this? This is a LocalScript in a GUI.

--Passtimed

local songs = {"Yeah", "Ok", "I Love You", "Hello"}
local display = script.Parent.SongBar
local id = script.Parent:WaitForChild("Music")

function choosesong()
    song = songs[math.random(1,#songs)]
    if song == "Yeah" then
        id.SoundId = "http://www.roblox.com/asset/?id=248543325"
    elseif song == "Ok" then
        id.SoundId = "http://www.roblox.com/asset/?id=250755837"
    elseif song == "I Love You" then
        id.SoundId = "http://www.roblox.com/asset/?id=225000651"
    elseif song == "Hello" then
        id.SoundId = "http://www.roblox.com/asset/?id=227526622"
    end
end

wait(1)
print("Song script loaded!")

while true do
    wait(.1)
    choosesong()
    display.Text = "Song: " .. song .. "!"
    id:Play()
    wait(120)
end
0
Press F9 in game, check for errors, and tell us what it says. funyun 958 — 9y

1 answer

Log in to vote
1
Answered by
funyun 958 Moderation Voter
9 years ago

Your current error is that "SongBar" needs load before you can do anything with it. Use the WaitForChild method to wait for it.

local display = script.Parent:WaitForChild("SongBar")
2
Thanks! Helped a lot! passtimed 45 — 9y
0
Theres an accept answer button to the right of all answers on your questions, click it if it answered your question. drew1017 330 — 9y
0
Can't find the button? passtimed 45 — 9y
0
Answered by funyun 80, 50 minutes ago, accept answer, report to staff. It's on the right of this comment section. funyun 958 — 9y
Ad

Answer this question