I keep getting this error message when someone enters a zone

Hello! I am having an issue where if any player enters a zone, that shows up. It can clutter the Output, and I am wondering how can I fix this. This is the error that it is receiving. It’s just a message/information not really an error or a warning so it doesn’t affect the script, but just clutters the Output, but I am wondering how can I prevent this from showing up? Everything is listed below.

local Zone = require(script.Change)
local Regions = game.Workspace.Folders._WORLDGUIS

local spawnWorld = Zone.new(Regions.spawnWorld.Part)
local snowWorld = Zone.new(Regions.snowWorld.Part)
-- Spawn World
spawnWorld.playerEntered:Connect(function(plr)
	MainPC = plr:WaitForChild("PlayerGui"):WaitForChild("Main PC")
--	print("player has entered Spawn World")
	MainPC.RightCoins["Coin Leaderstat"].Visible = true
	MainPC.RightMoney["Money Leaderstat"].Visible = true
	-- disable any other world GUIS
	MainPC.RightCoins["SnowCoin Leaderstat"].Visible = false
	MainPC.RightMoney["SnowCash Leaderstat"].Visible = false
end)

--spawnWorld.playerExited:Connect(function(plr)
--	print("player has exited Spawn World")
--	MainPC.RightCoins["Coin Leaderstat"].Visible = false
--	MainPC.RightMoney["Money Leaderstat"].Visible = false
--end)

-- Snow World
snowWorld.playerEntered:Connect(function(plr)
	MainPC = plr:WaitForChild("PlayerGui"):WaitForChild("Main PC")
	--	print("player has entered Snow World")
	MainPC.RightCoins["SnowCoin Leaderstat"].Visible = true
	MainPC.RightMoney["SnowCash Leaderstat"].Visible = true
	-- disable any other world GUIS
	MainPC.RightCoins["Coin Leaderstat"].Visible = false
	MainPC.RightMoney["Money Leaderstat"].Visible = false
end)

Thanks! Any help will be appreciated! :grinning_face_with_smiling_eyes:

If anyone knows, please let me know!

You don’t need to use :WaitForChild() on the player gui, as that would load in before the character (as far as I’m aware). See what message you get if you remove the wait for child

For that line, what do I put instead then? Do I put this?

	MainPC = plr.PlayerGui:WaitForChild("Main PC")

Yeah, try it, it might not work but it would give a more useful message than “Infinite yield possible”

Have you checked what’s actually inside of the player? Because the PlayerGui should be inside of every player

Yea obviously, is it the way I put the line of code? Cause the code still works, and If I haven’t mentioned, those lines of error show every time you enter a new zone.

The only other thing I can think of is the player not being defined correctly, but I assume that’s not the case, sorry but I don’t know what else to say

you’re all good. it’s not really an issue, more of just a clutter.

Could you provide the part of the code which gets and passes the plr object?

You could try printing the “plr” argument, so you will know if it is a player character.

Everything works, but it just shows that.

what do you mean exactly?

30 word

you can try printing the “plr” argument

spawnWorld.playerEntered:Connect(function(plr) 
print(plr)
	MainPC = plr:WaitForChild("PlayerGui"):WaitForChild("Main PC")
--	print("player has entered Spawn World")
	MainPC.RightCoins["Coin Leaderstat"].Visible = true
	MainPC.RightMoney["Money Leaderstat"].Visible = true
	-- disable any other world GUIS
	MainPC.RightCoins["SnowCoin Leaderstat"].Visible = false
	MainPC.RightMoney["SnowCash Leaderstat"].Visible = false
end)

Try doing

MainPC = plr:WaitForChild("PlayerGui", math.huge):WaitForChild("Main PC")

This removes the time limit on the WaitForChild, and PlayerGui will always be added.

1 Like

Perfect! This has fixed my issue! I really do appreciate it!

This has likely not fixed the issue, but just delayed the warning. PlayerGui should already be loaded in at this point, so it’s not a loading issue. Previously it would have warned after a few seconds, and it will likely do the same this time, but instead after - say a billion. So basically, anything you do with the PlayerGui will probably not run. I could be wrong in this, but I’m fairly sure this is the case.

Maybe. But I am just not sure why its doing this. It’s a clutter, and doesn’t affect the code. I really don’t know how to fix it. Also everything is running fine, I don’t see the message, and the thing that it is supposed to do, does it. I am going to sit in my game so I can see if it does get the error.