Trying to make ui disappear when theres 2 or more players

i know theres loads of topics on this but ive got this module script and it doesnt work. ty!

script:

local plrCheckModule = {}

function plrCheckModule.plrCount()

	while true do
		local playerCount = game.Players:GetChildren()

		if playerCount >= 2 then
			script.Parent.Parent.Visible = false
		else
			script.Parent.Parent.Visible = true
		end
		wait(2)
	end

end

return plrCheckModule

nvm i got it again ty!

solution for any1 stuck:

local plrCheckModule = {}

function plrCheckModule.plrCount()

	while true do
		local playerCount = #game.Players:GetPlayers()

	if playerCount >= 2 then
			script.Parent.Parent.Visible = false
		else
			script.Parent.Parent.Visible = true
		end
		wait(2)
	end

end

return plrCheckModule

Good job on finding the solution! One thing I’d like to suggest though is to use the while loop in a different script and call the function from there as it may look cleaner.

1 Like

thanks man!

ill take that into consideration for next time. i think i might leave it alone for the moment but yeah. tysm for the help tho! :smiley:

1 Like