Attempt to index nil with 'Text' error

I’m trying to make an overheadgui but I’ve run into an error, I don’t know how to fix it.

Script:

--- // VARIABLES // ---

local ServerStorageService = game:GetService('ServerStorage')
local RankUi = ServerStorageService:WaitForChild('RankGui')
local UsernameUi = ServerStorageService:WaitForChild('UsernameGui')

--- // MAIN CODE // ---

game.Players.PlayerAdded:Connect(function(plr)
		plr.CharacterAdded:Connect(function(char)
		
		local RankUiClone = RankUi:Clone()
		local UsernameUiClone = UsernameUi:Clone()
		
		RankUiClone.Parent = char.Head
		UsernameUiClone.Parent = char.Head
		
		RankUiClone.Frame:FindFirstChild('TextLabel').Text = plr:GetRoleInGroup(959294)
		UsernameUiClone.Frame:FindFirstChild('TextLabel').Text = plr.Name
	end)
end)

Dev Console Server Output:

3 Likes

There seems to be nothing wrong with the code, does RankUiClone contain a Frame and a TextLabel in the frame respectively?

Why are you using FindFirstChild as opposed to just directly referencing the TextLabel, when you’ve directly referenced absolutely everything else.

If you know there’s a chance that TextLabel doesn’t exist, then that immediately points towards the problem.

It’s very strange to use FindFirstChild unless the name is in a variable, contains characters such as a space, or it is not known whether it exists or not and therefore you can use the result in a conditional check.

Try using WaitForChild instead of FindFirstChild to find “TextLabel”

Yes:
image

It couldn’t find the TextLabel before, so I decided to try and use :FindFirstChild().

That should not make a difference though. If the TextLabel does not exist, then FindFirstChild() would return false. But it will not increase the chances of it being found.

The result in Developer Console Server output:

Also, it didn’t even put the GUI above my head.

Oh if it is an Infinite Yield, it means that the TextLabel does not exist. Most likely.

But it DOES exist:
image

In the output panel it says airsoft561.Head.RankGui.Frame:WaitForChild() and not the code you mentioned above, is that a different script?

Edit: My bad.

Is it a local script or server script?
Check both client and server in studio in play mode.

I forgot to say, I changed it on @TheMirrorGameCreator’s reply.

Also, I checked the explorer on studio, and somehow the text label DOES NOT exist for some reason.
image

Perhaps the head has not loaded in yet. Try this:

--- // VARIABLES // ---

local ServerStorageService = game:GetService('ServerStorage')
local RankUi = ServerStorageService:WaitForChild('RankGui')
local UsernameUi = ServerStorageService:WaitForChild('UsernameGui')

--- // MAIN CODE // ---

game.Players.PlayerAdded:Connect(function(plr)
		plr.CharacterAdded:Connect(function(char)
		
		local RankUiClone = RankUi:Clone()
		local UsernameUiClone = UsernameUi:Clone()
		
        local Head = char:WaitForChild("Head")
		RankUiClone.Parent = Head
		UsernameUiClone.Parent = Head
		
		RankUiClone.Frame:FindFirstChild('TextLabel').Text = plr:GetRoleInGroup(959294)
		UsernameUiClone.Frame:FindFirstChild('TextLabel').Text = plr.Name
	end)
end)

Server Script, also, client had nothing in it other then this which is not related to the script:


[No, it’s not a virus]

Then in that case, is there a possibility it is being deleted by another script? You could try using Alt+F (or shift+F I can’t remember) to search all scripts.

Back to square 1, same error.

Also, the textlabel is STILL not in the gui.
image

What about this? That is the only thing I can think of. Perhaps something like:

for i,v in pairs(character.Head:GetDescendants()) do
    if v:IsA("TextLabel") then
        v:Destroy()
    end
end

Only thing I can think of, though it would be a weird script though…

Checked, I searched up Destroy Delete and Remove in the advanced search tab, no scripts had it.

uhh maybe put those gui in replicated storage and change some of the scripts??!?!?