Trying to give group ranks certain tags in chat

local marketplaceService = game:GetService('MarketplaceService')
local replicatedStorage = game:GetService('ReplicatedStorage')

local functions = replicatedStorage:WaitForChild('Functions')
local chatChecker = functions:WaitForChild('ChatChecker')

local function returnInfo(player, actual, id, place, rank)
	if place == 'Pass' then
		if marketplaceService:UserOwnsGamePassAsync(actual.userId, id) then
			return true
		else
			return false
		end
	else
		if actual:IsInGroup(id) then
			return actual:GetRankInGroup(id)
		else
			return 0
		end
	end
end
 
chatChecker.OnServerInvoke = returnInfo

Below script is a separate script

-- ModuleScript in chat --
function sendInfo(player)
	
	local info = saves[player.UserId] 
	if not info then
	
		local priority = 0
		
		for key, value in pairs(ranks) do
			if chatChecker:InvokeServer(player, 3598451, 'Group', key) == 255 and value.priority > priority then
				info = {title = value.title, color = value.color, color0 = value.color0}
				priority = value.priority
				print(player.Name .. ' = Creator')
			elseif chatChecker:InvokeServer(player, 3598451, 'Group', key) == 195 and value.priority > priority then
				info = {title = value.title, color = value.color, color0 = value.color0}
				priority = value.priority
				print(player.Name .. ' = Mod')
			end
		end
	
		if info == nil then
			info = 'placeholder'
		end	
	
		saves[player.UserId] = info -- saves title info for easy reference
		return info
		
	else
		
		return info
	
	end
	
end

return sendInfo

These 2 scripts are in separate parts, and I’ve cut all the irrelevant stuff out of them (well to my knowledge at least) I believe the problem is inside the module script. I am trying to create tags for players in my group. So on the script at the top it checks to see if they are in the group, if not then it returns 0 (not in group/guest), if they are though it then returns their rank within the group (when I join it returns 255)

However in the module script, I have the lines to check what’s being returned by the RemoteFunctions, whether the number is 255 or 195. Now as I said before, it prints 255 when I chat, so it’s returning 255 for me, but it still gives me the mod rank (195).

I’m not sure if it has something to do with the metatable at the top of the modulescript? maybe because they all contain the same key (the group id). Any help would be greatly appreciated :smiley:

EDIT
I added prints, and it turns out that when each player chats it’s putting them in the right ‘position’ in the script. So if someone is rank 195, it prints their name = Mod, and if I chat it prints NinjoOnline = Creator. So the problem must be on this line:

info = {title = value.title, color = value.color, color0 = value.color0}

For some reason, whether the RemoteFunction returns as 255, or 195, it will always give that same info. Since there’s 2 info variables, it should theoretically give the second key for the 195 return.

Thank you,
Ninjo

4 Likes

you could use GetRoleInGroup to get the name of the rank or even use a table to change the chat tag for specific ranks,

1 Like

Is your game filtering enabled

How would this have any effect on the issue? If you see something in their code that would behave wrongly in one environment but correctly in the other, you should explain all that in your post rather than asking a question first. Whether or not they’re using filtering enabled won’t be of any use to them without an explanation.


As for the original post, I can’t tell where the issue would be. However, what I do know is that you should never have your client send a copy of the Player object. Use the one provided by the remote events and remote functions. Any client can decide they’re someone else, and you seem to be letting your server scripts believe the client.

2 Likes

Hey, @NinjoOnline.

I am a Roblox user who is currently learning LUA, and I saw this and decided to try it.
However, I am not quite sure where each script should go. May you give me some help about this, please? Where should the script with the returnInfo() function go, and where should the script with the sendInfo() function go?

The code in this thread is very specific to OP’s structure and not something you should be copy-pasting into your own code, since it leads to these kinds of issues as you posted:

  • Not knowing where each script goes
  • Not knowing what type of script to use

If you have a specific question about something, please have a look around the DevForum or search for answers where you can. Chat tags can be set via the Lua Chat System. As for setting tags on it, there are several threads relating to it.

Example:

Full query:
https://devforum.roblox.com/search?q=chat%20tags