Attempt to call missing method 'WaitForChild' of string

  1. I am currently making an elevator game, in said elevator game, i wanted to make it so that the music affects all players

  2. on servers with more than 1 person, this error shows up: ServerScriptService.Main:100: attempt to call missing method ‘WaitForChild’ of string

  3. I have no idea how to fix this, and nothing of this sort has appeared on the forums

1 Like

Try using “FindFirstChild” instead

1 Like

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 :sob:

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
image

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
1 Like

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

1 Like

Brother, show me the script. It seems you have put the reference of a string and not a instance.

sorry, here