Administrators Ingame Count Help

Okay so I want a UI to say how many specific players are in a game, someone told me to use:

local Settings = require(script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Settings)

local Admins = Settings.AdminIdsTable

local allAdmins = 0

local thing = script.Parent.Parent.chat

game.Players.PlayerAdded:Connect(function(plr)

	if table.find(Admins, plr.UserId) then
		allAdmins += 1
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	if table.find(Admins, plr.UserId) then
		allAdmins -= 1
	end
end)

print(allAdmins)

Anyways, the table of IDs are in a module script which is working. But whenever I ran it and printed the value it showed 0 even though my userId is in the table from the module script. Please help!

1 Like

If thats the whole script, you are printing the value only once when server is started, which is why it will print 0 since no players are in the game then. You should print the value every time it is changed.

Changed it to this, it still did not work.

local Settings = require(script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Settings)

local Admins = Settings.AdminIdsTable

local allAdmins = 0

local thing = script.Parent.Parent.chat

game.Players.PlayerAdded:Connect(function(plr)

	if table.find(Admins, plr.UserId) then
		allAdmins += 1
		thing.Text = allAdmins
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	if table.find(Admins, plr.UserId) then
		allAdmins -= 1
		thing.Text = allAdmins
	end
end)

What is that, what is this script, where is this script?

thats the text label where it should say the number.

What kind of script is it? (Chars)

Server not local

text limit

Right after this, print(Admins, plr.UserId) tell me what it prints. Also,

print(allAdmins) right above that line.

Nothing printed when I joined. I’m not sure why,

Oh, I think I know why. If this script is in a gui that is in StarterGui then it won’t work because that script will load in once the player is already in the game. So put that script in ServerScriptService, then get the clock from player:WaitForChild("PlayerGui")