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

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

Asked by 3 years ago
Edited 3 years ago

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

0
What line is the error message on? adieking1 69 — 3y
0
oh i just saw the last line of the question srry adieking1 69 — 3y

4 answers

Log in to vote
0
Answered by 3 years ago

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

local playerInfo = player:WaitForChild("playerInfo")
0
Still the same result, sorry. WatsPlayzROBLOX 80 — 3y
Ad
Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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.

0
I have a script that makes a folder named playerInfo, which has the teamPicked intValue WatsPlayzROBLOX 80 — 3y
Log in to vote
0
Answered by 3 years ago

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

0
didnt seem to work, if you could maybe write the script out that'd be great! WatsPlayzROBLOX 80 — 3y
Log in to vote
0
Answered by 3 years ago

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

Answer this question