{PlayerGui} Attempt to index nil with WaitForChild

  1. What do you want to achieve? Keep it simple and clear!

Hello, I want to make a Owner join notification on the screen instead of in the chat. So, when a player joins the game it will check the UserId if it matched then the remote event will fire to the server after that the server will make the notification visible to everybody on the server. After 5s the text will fade away and they will also get 50 extra coins added to their leaderstats.

  1. What is the issue? Include screenshots / videos if possible!

I have a problem with my script it gives me this error and the notification Gui doesn’t show to everyone.
ServerScriptService.Script:8: attempt to index nil with 'WaitForChild'

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried looking for solution on google as well as on developer forum but couldn’t find a fix to it.

-- localscript

local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local Notifier = script.Parent:WaitForChild("TextLabel")
local OwnerUserId = "1533601134"

local player = game.Players.PlayerAdded:Connect(function(player)
	local Character = player.Character or player.CharacterAdded:Wait()
	if player.UserId == OwnerUserId then
		Join:FireServer()
	end
end)
-- ServerScript

local tweenservice = game:GetService("TweenService")
local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local OwnerUserId = "1533601134"
local RunTime = 3 + 2

game.Players.PlayerAdded:Connect(function(player)
	local Character = player.Character or player.CharacterAdded:Wait()
	local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
	local Notifier = PlayerGui:WaitForChild("TextLabel")
	
	Join.OnServerEvent:Connect(function()
		if Notifier.Visible == false  then
			Notifier.Visible = true
			wait(RunTime)
			local A = TweenInfo.new(1, Enum.EasingStyle.Sine, 0, false, 0)
			local P = {Notifier.TextTransparency == 1}
			local X = tweenservice:Create(Notifier, A, P)
			X:Play()
		end
	end)
end)

You can’t use LocalPlayer in a Server script.
try changing it to:

local PlayerGui = player.PlayerGui
3 Likes

Oh, I have changed it but why does it says this in the output?
W is not a valid member of PlayerGui "Players.SingaporeSteadyLah.PlayerGui"

[EDIT] btw here is the script

local tweenservice = game:GetService("TweenService")
local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local OwnerUserId = "1533601134"
local RunTime = 3 + 2

game.Players.PlayerAdded:Connect(function(player)
	local Character = player.Character or player.CharacterAdded:Wait()
	local Player = game:GetService("Players")
	local Notifier = player.PlayerGui.W:WaitForChild("TextLabel")
	
	Join.OnServerEvent:Connect(function()
		if Notifier.Visible == false  then
			Notifier.Visible = true
			wait(RunTime)
			local A = TweenInfo.new(1, Enum.EasingStyle.Sine, 0, false, 0)
			local P = {Notifier.TextTransparency == 1}
			local X = tweenservice:Create(Notifier, A, P)
			X:Play()
		end
	end)
end)

I think You added an extra “W” there.
If “W” is a screenGui, you can do:

player.PlayerGui:WaitForChild("W").TextLabel

ok here is how I would go about this.

-- ServerScript (sorry for changing name of event)
local OwnerUserId = "1533601134"
game.Players.PlayerAdded:Connect(function(player)
    if player.UserId == OwnerUserId then
        OwnerJoinEvent:FireAllClients()
    end
end)
--client script
OwnerJoinEvent.OnClientEvent:Connect(function()
     --check local player is not the owner.
     --play effect
end)

Ok so I moved the owner join event firing to the server because the way you had it, an exploiter could fire that event from the client, server sees it as valid and cause problems. I then fired the client to play the effect on the client instead of the server because this removes load from the server. You shouldn’t have the wait for child problem as it is on the client.

If your WaitForChild errors persist, I recommend checking this awesome video by Sleitnick where he explains what causes the WaitForChild error and ways to get around it.

1 Like

Okay, so I did what you said I fired the remote event from the Server to the Client and make the Notification Gui visible, now no more errors but it print Owner not found on ServerScript when checking the UserId… Why does it do that?

-- LocalScript

local tweenservice = game:GetService("TweenService")
local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local OwnerUserId = "1533601134"
local Notifier = script.Parent:WaitForChild("TextLabel")
local RunTime = 3 + 2

game.Players.PlayerAdded:Connect(function(player)
	Join.OnClientEvent:Connect(function()
		if player.UserId == OwnerUserId then
			print("Ensureing UserId Match with OwnerUserId")
			print(OwnerUserId)
			if Notifier.Visible == false then
				Notifier.Text = "{Owner} - SingaporeSteadyLah has joined the game! You received 50 extra Coins!"
				Notifier.Visible = true
				wait(RunTime)
				local A = TweenInfo.new(1, Enum.EasingStyle.Sine, 0, false, 0)
				local P = {Notifier.TextTransparency == 1}
				local X = tweenservice:Create(Notifier, A, P)
				X:Play()
			else
				print("Error or Owner not found!")
			end
		end
	end)
end)
-- ServerScript

local Join = game.ReplicatedStorage.Events:WaitForChild("Join")
local OwnerUserId = "1533601134"

game.Players.PlayerAdded:Connect(function(player)
	local Character = player.Character or player.CharacterAdded:Wait()
	if player.UserId == OwnerUserId then
		print("Owner found!")
		Join.FireAllClient()
	else
		print("Owner not found!")
	end
end)

Because you’ve set the OwnerUserId to a string, but player.UserId is a number. Just remove the quotes.

2 Likes

The OwnerUserId is a string. Change it to just 1533601134

2 Likes

Man I always forgot about that. I thought the UserId is a string xD

Also i see a typo in the code

Join.FireAllClient() should be Join:FireAllClients()
1 Like

For your information, having the local script is absolutely useless and redundant. You can hande all of this on the server without any events, like this:

-- Server script

local players = game.Players
local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local ownerId = "1533601134"
local notifier = replicatedStorage:WaitForChild("Notifier") -- Put the notifier in ReplicatedStorage
local waitTime = 3 + 2

players .PlayerAdded:Connect(function(player)
	if player.UserId == ownerId then
		print("Owner found!")
		notifier.Text = "{Owner} - SingaporeSteadyLah has joined the game! You received 50 extra Coins!"
		notifier.Visible = true
		
		for i = 0, #players :GetPlayers(), 1 do
			notifier.Parent = players[i]:WaitForChild("PlayerGui"):WaitForChild("YourScreenGuiNameHere")
		end

		task.wait(waitTime)
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, 0, false, 0)
		local tween = tweenService:Create(notifier, tweenInfo , {TextTransparency = 1})
		tween:Play()
	else
		print("Owner not found!")
	end
end)
2 Likes

Big thanks to you guys! :heart: :pray: This script wouldn’t work without your help :smiley:

Hey there… May I know What is task.Wait() and why would you use it?

wait() should never be used. Even if there’s no parameter, it can wait up to 1 second. task.wait() is much more accurate and if you compare wait() vs task.wait() (with no seconds provided), task.wait() is 2x times faster. But even if you give it an amount of seconds to wait, like wait(5), the default function is still much less accurate. Always use task.wait() to wait a precise amount of time.

Umm… Owner join Notification Gui on the screen instead of in the chat

because of this thread i learnt about the task library update and no longer have to use a custom thread module to handle wait and fastspawn. I really should check announcements more often.

How do I fix this FireAllClients error?
Expected ':' not '.' calling member function FireAllClients

oh my bad, its meant to be Join:FireAllClients()

Oh, btw the Notification Gui is not showing it is also not printing in the output only the print(“Owner found!”)