Attempt to index nil with 'WaitForChild'?

Hellow everyone!
While pressing the key, I encountered a problem such as " attempt to index nil with ‘WaitForChild’ " :


image

local Player = game.Players.LocalPlayer
local Button = script.Parent.Parent:WaitForChild("ClickButton")
script.Parent.Parent.ClickButton.MouseButton1Click:Connect(function(plr, plrGui)
	if plr:WaitForChild("leaderstats"):WaitForChild("DislikesBoost") > 0 then
		game.ServerScriptService:WaitForChild("DislikesManeger").Disabled = true
		game.ServerScriptService:WaitForChild("BoostedScript").Disabled = false
	end
end)

The place of the problem:

if plr:WaitForChild("leaderstats"):WaitForChild("DislikesBoost") > 0 then

A few errors I can see is that you are defining a local player in a server script which wouldn’t work. I recommend moving it to a local script and firing an event to the server to change the value. Also, the function has plr, plrGui as parameters which it wouldn’t send since I believe MouseButton1Click doesn’t send any arguments.

1 Like