I am receiving "attempt to index nil with 'FindFirstChild'" from two of my scripts, namely ChatHandler and ChangeNameScript, on account of identifying a GUI placed in the player's head by my localscript, Name title giver.
Specifically, I am getting "Workspace.ChatHandler:19: attempt to index nil with 'FindFirstChild'" and "ServerScriptService.ChangeNameScript:8: attempt to index nil with 'FindFirstChild'".
The ChatHandler and ChangeNameScript are supposed to identify the text of the nametag (NameGui.NameLabel.Text) provided by Name title giver, but it does not. The NameLabel, NameGui, and player's head exist at the time in which the scripts go to identify them, however, they don't identify them. I am at my wit's end as to why. I appreciate any response, help, or suggestion. I am new to coding and I am truly lost as to what I am doing wrong. PLEASE tell me if you need any further clarification, I will gladfully provide it. Thank you so much
Below are my scripts and screenshots of my workspace.
Here is my ChatHandler script:
local chatstorage = game.Workspace.ChatStorage
local onChatInputted = game.ReplicatedStorage:WaitForChild("OnChatInputted")
onChatInputted.OnServerEvent:Connect(function(plr, msg)
local filteredText
local filteredString
local char = plr.Character or plr.CharacterAdded:Wait()
local Head = char:WaitForChild("Head")
local stringval = Instance.new('StringValue', chatstorage)
local success, errormsg = pcall(function()
filteredText = game:GetService("TextService"):FilterStringAsync(msg, plr.UserId)
end)
if success then
local success2, errormsg2 = pcall(function()
filteredString = filteredText:GetNonChatStringForBroadcastAsync()
end)
if success2 then
local nameGui = Head:FindFirstChild("NameGui")
local nameLabel = nameGui:FindFirstChild("NameLabel")
stringval.Name = '['..plr.Team.Name..'] '..nameLabel.Text..': '..string.upper(string.sub(filteredString,1,1))..string.sub(filteredString,2)
local RS = game:GetService("ReplicatedStorage")
local Chat = RS:WaitForChild("Chat"):Clone()
local Bubble = Chat:WaitForChild("Bubble")
local TextLabel = Bubble:WaitForChild("TextLabel")
TextLabel.Text = string.upper(string.sub(filteredString,1,1))..string.sub(filteredString,2)
Chat.Adornee = Head
Chat.Parent = Head
if string.len(string.upper(string.sub(filteredString,1,1))..string.sub(filteredString,2))> 15 then game.Debris:AddItem(Chat, 9) else game.Debris:AddItem(Chat, 4) end
else
warn(errormsg2)
stringval:Destroy()
end
else
warn(errormsg)
stringval:Destroy()
end
end)
Here is my ChangeNameScript:
local remoteEvent = game.ReplicatedStorage.NameChangeEvent
remoteEvent.OnServerEvent:Connect(function(plr, name)
local char = plr.Character or plr.CharacterAdded:Wait()
local filteredName = game:GetService("TextService"):FilterStringAsync(name, plr.UserId)
local filteredNameAsString = filteredName:GetNonChatStringForBroadcastAsync()
local nameGui = char.Head:FindFirstChild("NameGui")
local nameLabel = nameGui:FindFirstChild("NameLabel")
nameLabel.Text = filteredNameAsString
end)
Here is my Name title giver script:
local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local Teams = game:GetService("Teams")
local Character = Player.Character
function NameGiver(Player)
print("Name given: START")
local nameGui = Instance.new("BillboardGui", Character.Head)
nameGui.StudsOffset = Vector3.new(0, 2, 0)
nameGui.MaxDistance = 30
nameGui.Size = UDim2.new(0, 200, 0, 50)
nameGui.Name = "NameGui"
local nameLabel = Instance.new("TextLabel")
nameLabel.Text = game.Players.LocalPlayer.Name
nameLabel.TextStrokeTransparency = 0
nameLabel.TextScaled = true
nameLabel.Font = "Fantasy"
nameLabel.Size = UDim2.new(0, 200, 0, 50)
nameLabel.BackgroundTransparency = 1
nameLabel.TextColor3 = game.Players.LocalPlayer.TeamColor.Color
nameLabel.Name = "NameLabel"
nameLabel.Parent = nameGui
print("Name given: FINISHED")
end
-- Manual detection of a property change
local function onChanged(property)
if property == "Team" then
print("TEAM CHANGED")
end
end
-- Connect both events
Player:GetPropertyChangedSignal("Team"):Connect(NameGiver)
Player.Changed:Connect(onChanged)

2 comments
Thank you. How would I add NameGui not clientsided? Is it possible to add NameGui not clientsided via localscript or would I have to rewrite it in a normal script somehow?
you would add it exactly the same way, move the namegiver function to a script and use characteradded event to give it that GUI