-
I am currently making an elevator game, in said elevator game, i wanted to make it so that the music affects all players
-
on servers with more than 1 person, this error shows up: ServerScriptService.Main:100: attempt to call missing method âWaitForChildâ of string
-
I have no idea how to fix this, and nothing of this sort has appeared on the forums
Try using âFindFirstChildâ instead
error is now âattempt to call missing method âFindFirstChildâ of stringâ ( exact same thing execpt its âFindFirstChildâ
Itâs because u can only use wait for child and find first child on models or folders, u cant use them on strings
Quick Example :
Instead of doing this:
local floor = âFloor1â â wrong: string
floor:WaitForChild(âPointsâ)
Do this :
local floorName = âFloor1â
local floor = tycoon:FindFirstChild(floorName) â now floor is an Instance
if floor then
floor:WaitForChild(âPointsâ)
end
wait âwait for childâ and âfind first childâ doesnt work on sounds?
u must convert ur string to an instance
your gui âMusicâ contains strings, thats the reason why ur script isnt working. use a if statement like :
if v:IsA(âTextLabelâ) then continue end
whats âtycoonâ in this example?
in this case its a string, idk why u asking me that
did you even read the error ![]()
anyway, can you print v and v:GetChildren()?
also, youâre converting a string to a sound instance (i assume .Music is a sound), just do AllMusic without assigning a value to it, you donât have to assign values to variables
local music
-- your for loop
music = whatever
srry im kinda new to scripting im tryna do my best xd
we cant see the output so i dont know which line is the wrong one
nvm i just saw this
![]()
itâs because AllMusic is a string, and you try to set it to a sound instance
for _, player in players:GetPlayers() do -- also why are you looping through every single player in the game?
if player.PlayerGui:FindFirstChild('Music') then -- you have to use FindFirstChild, i'll explain below
print('yes music')
allMusic = player.PlayerGui:FindFirstChild('Music')
end
end
the reason why you need to use FindFirstChild is because the method returns an instance or nil, if no instance of given name was found
WaitForChild on the other hand is used to yield code, you canât use it in conditions
Replace the line MountainMusic = AllMusic:WaitForChild... with:
local AllMusic = nil
if AllMusic then
MountainMusic = AllMusic:WaitForChild("MountainMusic")
end
nevermind this isnt the solution cuz it still gives me an error:
attempt to index nil with âPlayâ
once it actually tries to play it
( theres also a second audio track called âCurrentSongâ that uses AllMusic to find it )
The way you are searching for the next song is wrong.
It should be:
local music = --Put the music path here.
local MountainMusic = music:WaitForChild("MountainMusic")
attempt to call missing method âWaitForChildâ of string
⌠weâre back at the start
Brother, show me the script. It seems you have put the reference of a string and not a instance.




