Attempt to index nil with 'FindFirstChild

Hi can anyone fix this I have a Signtool and I don’t know how to fix error

local player = game.Players.LocalPlayer

local TextMsg = script.Parent

TextMsg.Changed:Connect(function()
if player.Character:FindFirstChild(“Sign”) then
player.Character[“Sign”]:WaitForChild(“UpdateSign”):FireServer(TextMsg.Text)
end
end)

4 Likes

The only place I see FindFirstChild used is on the character so maybe the player doesn’t have a character…?

6 Likes

hmm, try printing if character exists (print(player.Character ~= nil)) before the if statement and see when it printed. the TextMsg might’ve changed before the player’s character loaded (or the player fell to the void then edited TextMsg). like what ridiche said

for extra safety, try connecting TextMsg:GetPropertyChangedSignal("Text") instead of TextMsg.Changed cuz the latter can fire everytime one of its properties changes, not just Text

local player = game.Players.LocalPlayer

local TextMsg = script.Parent

TextMsg:GetPropertyChangedSignal("Text"):Connect(function()
    if player.Character:FindFirstChild("Sign") then
        player.Character["Sign"]:WaitForChild("UpdateSign"):FireServer(TextMsg.Text)
    end
end)
1 Like

Here’s your solution:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() -- Either the character (if its loaded) or wait for it to be loaded

local TextMsg = script.Parent

TextMsg.Changed:Connect(function()
if player.Character:FindFirstChild(“Sign”) then
player.Character[“Sign”]:WaitForChild(“UpdateSign”):FireServer(TextMsg.Text)
end
end)

You need to wait until the character is actually loaded before trying to run code!

2 Likes
local PlayerService = game:GetService("Players")

local Player = PlayerService.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local TextMsg = script.Parent

TextMsg:GetPropertyChangedSignal("Text"):Connect(function()
	local Sign = Character and Character:FindFirstChild("Sign")
	local UpdateSign = Sign and Sign:FindFirstChild("UpdateSign")

	if UpdateSign then
		UpdateSign:FireServer(TextMsg.Text)
	end
end)
3 Likes