I want to find out why the error is caused + how to fix it and why it sometimes doesn’t show any errors at all.
The issue is that on line 3, it sometimes doesn’t seem to register that Music exists so it shows an error: “… is not a valid member of …”. However, it sometimes works perfectly fine without any errors displaying.
I have tried adding a WaitForChild to wait for the Music to load before it’s being activated and print(). I haven’t found any solutions on the devforum. Both didn’t fix the problem.
This LocalScript is in a GUI button. It’s a button to turn on/off the music when clicked. The music is in the Workspace. It’s there and not in SoundService because the music is strictly only playing in the lobby and no where else.
The LocalScript code:
local Button = script.Parent
local Workspace = game:GetService("Workspace")
local Music = Workspace:WaitForChild("Lobby").MusicPlayer.Music:GetDescendants()
-- The rest of the code is just the Button function. That part itself works perfectly fine. The problem is on line 3.
likely related to StreamingEnabled, in addition to using wait for child, I recommend turning this setting off in Workspace Properties > StreamingEnabled
Streaming is better for performance, so you don’t load the entire world at once. But you basically have to design your entire experience around it if you enable it
If it’s small, why would the MusicPlayer be outside of the streaming radius? I think that you should just add WaitForChild too all instances on line 3 and renewable streaming. You could also see about increasing the streaming radius.
I assume it’s something with the loading the game part. I never get it when I teleport from the lobby to the map. It’s only when it’s loading the game.
It’s just the default Roblox loading screen. The spawn is 20 studs-ish away from the Music player. The map and the lobby is within the radius by 24 studs.
Right. I just want you to test this; renable streaming and edit line 3 to be this and let me know if it errors or not. It’s erroring because the script is trying to find MusicPlayer inside Lobby, which hasn’t loaded in yet.
local Music = Workspace:WaitForChild("Lobby"):WaitForChild("MusicPlayer"):WaitForChild("Music"):GetDescendants()