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!
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.
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)
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")