Need help with MessagingService

I am trying to create a list of online Admins.

I have a list of problems, I’ve spent days researching but I have no idea what I’m doing.

  1. When an admin joins, it removes all current players in the admin list and only puts the admin that just joined.

  2. I am trying to make it so that when an admin leaves, it keeps everyone else on the admin list besides the admin that just left.

  3. Trying to get the group rank of a player and displaying it on the list, but I wanna worry about that later.

There are 2 admins in the game, but only 1 shows and it was the admin that last joined.
image_2022-09-22_200007610

LocalScript for AdminList

--> Main Locals <--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunAdminList = ReplicatedStorage.Admin:WaitForChild("RunAdminList")
local httpsService = game:GetService("HttpService")
local Frame = script.Parent
local GroupId = 6442622
local Players = game:GetService("Players")


--> Online Admin List <--
local plrList = Frame:WaitForChild("AdminPlayerList")
local plrChosen = nil

RunAdminList.OnClientEvent:Connect(function(AdminPlayer)
	for i, child in pairs(plrList:GetChildren()) do

		if child:IsA("Frame") then child:Destroy() end
	end

	local admin = script.AdminFrame:Clone()
	
	local adminlistTable = {}
	table.insert(adminlistTable, AdminPlayer)
	
	for i, admins in pairs(adminlistTable) do
		
		local adminsId = Players:GetUserIdFromNameAsync(admins)
		
		local userId = adminsId
		local profile = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size60x60)

		admin.AdminProfile.Image = profile
		admin.AdminName.Text = admins
		admin.Parent = plrList
	end
	--RunAdminList:FireServer(AdminPlayer)
	
	--[[local data = httpsService:GetAsync("https://groups.roproxy.com/v2/users/{userId}/groups/roles")

	for i, v in ipairs(data) do
		if v.group.id == GroupId then
			if v.role.id == 255 then
				admin.GroupRank.Text = "🍓Owner🍓"
			elseif v.role.id == 253 then
				admin.GroupRank.Text = "🔨Developers🔨"
			elseif v.role.id == 252 then
				admin.GroupRank.Text = "🚨Moderators🚨"
			end
		end
	end--]]

end)

The location of the script and frame for the list.
image_2022-09-22_200157294

Script for MessagingService

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage.Admin:WaitForChild("RunAdminList")
local MessagingService = game:GetService("MessagingService")
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
local httpsService = game:GetService("HttpService")

local GroupId = 6442622

Players.PlayerAdded:Connect(function(player)
	if player:GetRankInGroup(GroupId) == 255 or player:GetRankInGroup(GroupId) == 253 or player:GetRankInGroup(GroupId) == 252 then
		local playerID = player.UserId
		local text = playerID
		local filteredTextResult = TextService:FilterStringAsync(text, playerID)
		local message = player.Name
		MessagingService:PublishAsync("GetAllAdmins", message)
	end
end)


MessagingService:SubscribeAsync("GetAllAdmins", function(message)
	print(message.Data)
	print(message.Sent)
	event:FireAllClients(message.Data)
end)



event.OnServerEvent:Connect(function(AdminPlayer)

	local data = httpsService:GetAsync("https://groups.roproxy.com/v1/groups/{groupId}/roles/{roleSetId}/users")

	local admin = script.Parent.Parent.StarterGui.AdminPanel.Output.Home.HomeScript.AdminFrame

	for i, v in ipairs(data) do
		if v.group.id == GroupId then
			if v.role.id == 255 then
				admin.GroupRank.Text = "🍓Owner🍓"
			elseif v.role.id == 253 then
				admin.GroupRank.Text = "🔨Developers🔨"
			elseif v.role.id == 252 then
				admin.GroupRank.Text = "🚨Moderators🚨"
			end
		end
	end

end)

The location of the script is in ServerScriptService

I hope anyone can help me out with this, I’ve been working on this for over 8 hours now. I’m still an amateur at scripting and this is my first time using MessageService. Thanks!

1 Like

Your script deletes the plrList and replaces it with an Admin list.

What if you made a layout so you don’t have to delete them?

How would this work and can you link anything that does this?

I do not have any links, but I can explain it.

You have a Scrolling Frame.

You have a UiListLayout inside of the Scrolling Frame.

You will also have the different “Teams” or Catagories in the Scrolling Frame. (As Normal Frames)

The players will be Normal Frames with a TextLabel. Which will go inside of the “Teams” or Catagories.

I have a UiListLayout, but what will the Teams or Categories help with? The admins are already separated from the regular players? I don’t really understand.

Let me make a visual example, give me a minute.

Okay, basically. it looks like this at the start:
PlayerLeaderboardExample

The Catagory or Team is the white text.

The white transparent frames are the simulated players.

How you do this is very simple and will save you a lot of time.

First, this is how I have my Gui formatted.

PlayerLeaderboardExample2

How to correctly place the Ui in the spots.

To get the Gui in the correct position is very simple.

First, you want to locate the LayoutOrder property, which can be found under the ClassName.

LeaderboardExample3

The lower the number the higher it will be on the leaderboard.

I set my Admin Frame to 1.
All the players that are suppose to be in the Admin Frame are set to 2.

I repeated this for the Others Frame. As seen below.

LeaderboardExample4

The Others Frame’s Players are set to LayoutOrder 4.

How to turn this into a script

So, how would we put this into script form?

Simply, your script already checks the player. So, if they are an Admin you can make the Admin Team and put them under it. (You want to make checks incase you already have the admin team.)

If they are not apart of the Admin Team put them in the respected Team.

If you need help with the scripting let me know.

I understand this, but I do not need the other players. I am trying to get all admins on every server, and checking if they are online. If they are not online, they will not be on the list.

Or do you want me to put offline admins in the others section, and the online admins in the online section?

You can use this same method for the online admins only. You want to follow what I did, but without the Others.

As long as you can get all the online admins, you can do this.

I believe I am able to add the admins to the Online list, but how will I remove the admins from the list? I can make the disconnected part for MessageService. But I do not know about the local script.

Can you show me where / how you check when they are offline?

You can always make a

PlayerRemoving

Then, check if they are in the leaderboard and destroy that Textlabel.

Okay, I will have to add this next week. As I am busy this weekend. Thank you for your help, I tell you if it works or not.

I didn’t add to check if the admin is offline yet, because I was trying to make the admins show on the list correctly first.

That is okay man, no problem. Have a good night.