Attempt to index nil with 'WaitForChild'

No idea why this is occuring now, the script used to work perfectly?

I’m getting an error on a value being nil but the player has the value,

script :

local plrs = game.Players
local sss = game.ServerScriptService
local chatService = require(sss:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
local groupID = 5336178

chatService.SpeakerAdded:Connect(function(plr)

	local speaker = chatService:GetSpeaker(plr)	

	-- COPY FROM THIS
	repeat wait() until
	plr.leaderstats:WaitForChild("ChatValues").Owner.Value == true
	if plr.leaderstats:WaitForChild("ChatValues").Owner.Value == true then
		speaker:SetExtraData('NameColor', Color3.fromRGB(85, 0, 255))
		speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
		speaker:SetExtraData('Tags', {{TagText = 'Owner', TagColor = Color3.fromRGB(85, 255, 127)}})
		print("Gave the owner a special chat tag and chat color!")		
	end
end)

chatService.SpeakerAdded:Connect(function(plr)
	local speaker = chatService:GetSpeaker(plr)	
	repeat wait() until
	plr.leaderstats:WaitForChild("ChatValues").Staff.Value == true
	if plr.leaderstats:WaitForChild("ChatValues").Staff.Value == true then
		speaker:SetExtraData('Tags', {{TagText = 'Staff', TagColor = Color3.fromRGB(255, 170, 0)}})
		print("Gave the Staff Member a special chat tag and chat color!")
	end
end)

chatService.SpeakerAdded:Connect(function(plr)
	local speaker = chatService:GetSpeaker(plr)	
	repeat wait() until
	plr.leaderstats:WaitForChild("ChatValues").Contributor.Value == true
	if plr.leaderstats:WaitForChild("ChatValues").Contributor.Value == true then
		speaker:SetExtraData('Tags', {{TagText = 'Contributor', TagColor = Color3.fromRGB(85, 255, 255)}})
		print("Gave the Contributor a special chat tag and chat color!")		
	end
end)

chatService.SpeakerAdded:Connect(function(plr)
	local speaker = chatService:GetSpeaker(plr)	
	repeat wait() until
	plr.leaderstats:WaitForChild("ChatValues").Tester.Value == true
	if plr.leaderstats:WaitForChild("ChatValues").Tester.Value == true then
		speaker:SetExtraData('Tags', {{TagText = 'Tester', TagColor = Color3.fromRGB(255, 255, 0)}})
		print("Gave the Tester a special chat tag and chat color!")		
	end
end)

Errors occur on lines 12, 24, 34, 44 where it is supposed to identify the value but it doesn’t work.

The children of the player/where the values are located :

image

Help would be appreciated thank you!

Try adding this at he top of each event

plr = plrs:WairtForChild(plr)

Also, can’t you just merge all events into one?

Not the best, but this should work:

local plrs = game.Players
local sss = game.ServerScriptService
local chatService = require(sss:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
local groupID = 5336178

chatService.SpeakerAdded:Connect(function(plrname)
    local plr = plrs:WaitForChild(plrname)
	local speaker = chatService:GetSpeaker(plrname)	

	-- COPY FROM THIS
	if plr.leaderstats:WaitForChild("ChatValues").Owner.Value then
		speaker:SetExtraData('NameColor', Color3.fromRGB(85, 0, 255))
		speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
		speaker:SetExtraData('Tags', {{TagText = 'Owner', TagColor = Color3.fromRGB(85, 255, 127)}})
		print("Gave the owner a special chat tag and chat color!")
    elseif plr.leaderstats:WaitForChild("ChatValues").Staff.Value then
		speaker:SetExtraData('Tags', {{TagText = 'Staff', TagColor = Color3.fromRGB(255, 170, 0)}})
		print("Gave the Staff Member a special chat tag and chat color!")
	elseif plr.leaderstats:WaitForChild("ChatValues").Contributor.Value then
		speaker:SetExtraData('Tags', {{TagText = 'Contributor', TagColor = Color3.fromRGB(85, 255, 255)}})
		print("Gave the Contributor a special chat tag and chat color!")
    elseif plr.leaderstats:WaitForChild("ChatValues").Tester.Value then
		speaker:SetExtraData('Tags', {{TagText = 'Tester', TagColor = Color3.fromRGB(255, 255, 0)}})
		print("Gave the Tester a special chat tag and chat color!")
	end
end)

Just do something like leaderstats:WaitForChild("ChatValues"):WaitForChild("Owner").Value It might fix it as you are not sure whether it loaded this items or not and try making your code with if statements it will be way more efficient and way smallee