Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How could i fix 'attempt to index nil with 'waitforchild'?

What i am trying to do is, when the player selects the red team, it changes the value of intValue teamPicked to 1, and stringValue of TEAM to "blue", the error im getting is attempt to index nil with 'WaitForChild', ive also tried not using waitforchild and some other ways but it still did not work. I apologize if there is not enough information, but this is all i have so far:

local player = game.Players.LocalPlayer
local plr = script.Parent.Parent.Parent.Parent.Name
local playerInfo = game.Players.LocalPlayer:WaitForChild("playerInfo") --<
local teamPicked = player.playerInfo:WaitForChild("teamPicked")

script.Parent.MouseButton1Click:connect(function()
    game.Players[plr].Team = game.Teams.Blue
    game.Players[plr].TeamColor = BrickColor.new("Lapis")
script.Parent.Parent.Enabled = false -- the whole screenGui
teamPicked.Value = 1 -- intValue
game.ReplicatedStorage.TEAM = "blue" -- this is a stringValue
end)

the problem is in row 3

2 comments

0

What line is the error message on?

0

oh i just saw the last line of the question srry

4 answers

Just do. i don't think it would fix the problem but it might

local playerInfo = player:WaitForChild("playerInfo")

1 comment

0

Still the same result, sorry.

The playerInfo does not exist, check if it is there. This error means that you tried to do something to nil (nothing). Maybe the playerInfo is in character, find it's location and check again.

1 comment

0

I have a script that makes a folder named playerInfo, which has the teamPicked intValue

Characters automatically come with the .Archivable property off! All you need to fix is turn it on before doing the WaitForChild operation

1 comment

0

didnt seem to work, if you could maybe write the script out that'd be great!

Seems like i found out the problem myself, thanks for trying to help guys, appreciate the support!

This discussion is preserved as it was. New answers, comments, and votes are closed.