How to make the Chatwindow visible only to certain ranks?

So, I’m trying to make a sort of “chatlogs system”, where only the staff is able to see the chat window with the convos, while normal players only see the chatbar to type.

I found a script that allowed to edit these settings for everyone, this one:
Local script placed in Replicated First

local ChatService = game:GetService("Chat")
    ChatService:RegisterChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, function()
        return {BubbleChatEnabled = true, ClassicChatEnabled = true}

I tried to “readapt” the script so that only certain ranks can see the window:
Local script placed in Replicated first

--Chatlogs for Staff
local plr = game.Players.LocalPlayer

if plr:GetRankInGroup(6753419) < 11 then
	local ChatService = game:GetService("Chat")
	ChatService:RegisterChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, function()
		return {BubbleChatEnabled = true, ClassicChatEnabled = false}
	end)
	
else
	local ChatService = game:GetService("Chat")
	ChatService:RegisterChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, function()
		return {BubbleChatEnabled = true, ClassicChatEnabled = true}
	end)
end

Sadly it doesn’t seem to work and the console reports no errors, so I have no idea what to change.

1 Like

You’re using the wrong code for the group role check as you’re using :GetRankInGroup, instead you should be using :GetRoleInGroup.

According to the Wiki, the correct code is :GetRankInGroup, which is exactly what I’m using, and not :GetRoleInGroup… :sob:
Wiki
Error: Screenshot by Lightshot

Update: turns out the script works but not perfectly. While almost all the ranks below 11 can’t see the chatlogs, those who are not in the group and those who are rank 1, for some reason can.
I tried the following fix:


--Chatlogs for Staff
local plr = game.Players.LocalPlayer
local ChatService = game:GetService("Chat")

if plr:GetRankInGroup(6753419) < 10 then
	ChatService:RegisterChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, function()
		return {BubbleChatEnabled = true, ClassicChatEnabled = false}
	end)
	
elseif plr:GetRankInGroup(6753419) == 0 then
	ChatService:RegisterChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, function()
		return {BubbleChatEnabled = true, ClassicChatEnabled = false}
	end)
elseif plr:GetRankInGroup(6753419) == 1 then
	ChatService:RegisterChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, function()
		return {BubbleChatEnabled = true, ClassicChatEnabled = false}
	end)

else
	ChatService:RegisterChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, function()
		return {BubbleChatEnabled = true, ClassicChatEnabled = true}
	end)
end

Still no result…

A good idea is to output what GetRankInGroup is returning and see what numbers are coming up so you can understand the problem better.

Also, here’s a bit more pretty code for you.

--Chatlogs for Staff
local Player = game.Players.LocalPlayer
local ChatService = game:GetService("Chat")

ChatService:RegisterChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, function()
	return {
		BubbleChatEnabled = true, 
		ClassicChatEnabled = (Player:GetRankInGroup(6753419) >= 11)
	}
end)

(Player:GetRankInGroup(6753419) >= 11) is true when the rank is greater or equal to 11.

By using print? I’m probably missing the point, but how could that help?

Thank you so much for the code! I’ll test it now, but I’m a bit confused, how can the script set the value to false or true based on the rank without an if statement? Is that value always false by default?
Sorry for the late answer btw ^^"

Yes test the system using the print() function as it can help you debug the script, you might also want to print the GetRankInGroup function as @Ninja_Deer said

1 Like

Right now, you don’t know why rank 0 or 1 players are not having their chats disabled. The best way to figure out what’s going on is to print the returned value from GetRankInGroup. It gives you a better look at why it’s doing what it’s doing.

If statements test boolean expressions and run a certain block of code if it is true.

if BOOLEAN_EXPRESSION then
    --action here
end

The code between the if and then always has to be a boolean expression. A boolean expression is a piece of code that evaluates to either true or false. Symbols like ==, >=, <, etc. are part of a boolean expression. Also, a simple true or false is also considered a boolean expression. As you may have guessed, any boolean can replaced by a boolean expression as they are effectively the same thing.

Therefore, instead of doing something like this:

local x = (5 < 11) -- evaluates to `true`

if x then
    print(true)
else
    print(false)
end

I am more simply doing this:

print(5 < 11) -- outputs true
1 Like

Alright I tried printing the players’ rank using this code:

game.Players.PlayerAdded:Connect(function(player)
	print(player:GetRoleInGroup(6753419)) --tried both Role and Rank variations btw
end)

The console just tells me the rank, as it should, but doesn’t really help…

I also tried your code and now it doesn’t work at all :skull: am I doing something wrong? I’m putting it in a LocalScript in ReplicatedFirst.
By the way, thank you for the explanation regarding booleans, I totally get the logic behind it now, will come handy in the future for sure. :slight_smile:

EDIT: I’ve retested the codes, both mine and @Ninja_Deer, multiple times under different conditions, sometimes by ranking myself to a lower rank so that I could not see the chatlogs or by testing it with other people in-game or by myself in studio by increasing the rank requirement above mine. Weirdly, I noticed that the scripts DO work, but only in studio, I’m having issues only in-game. I’m really confused.

Figured out the issue. By the time the client gets the player’s rank, the chat window is already created. You can’t directly set those two boolean after as it won’t check those boolean again after it has already finished setting up the chat script.

Other than editing Roblox’s chat scripts, I’m not familiar with a way to do this. I’m not familiar enough with their chat system either as I usually end up making my own anyway.

Sorry about that. :frowning:

1 Like

You’re close, however ChatCallback scripts need to run fast, and having the yielding GetRankInGroup makes them not work.
Here’s the code you should be using:

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Chat, Player:GetRankInGroup(6753419) >= 11)

Use this for after the game has loaded, use CharCallbacks for when the game is loading (ie, a script in replicatedFirst with no yielding functions)

1 Like

Wouldn’t this disable the chat bar along with chat bubbles as well?

1 Like

I don’t know, I think not, but it actually works :slight_smile:

Makes sense but it also doesn’t to be honest… As I said in my previous message, the scripts work indeed, but only in studio. I don’t think the game and chat are loaded differently in studio, are they?

Please, no need to apologize!! I appreciate your help immensely, thank you so much for trying and taking the time to answer :slight_smile:

Really sorry for the late reply, I’ll try the code as soon as possible and let you know. In the meanwhile: what’s a yielding function? I tried looking on the Wiki but didn’t really help… :skull:

Also, wouldn’t this disable the whole chat, as @Ninja_Deer said? I’m trying to disable just the chatlogs for those ranked below 11, not the chatbar and bubblechat… ^^"

yielding just means it waits for something to finish, for example, this would be a yielding function:

function Yield()
    wait(1)
    return Value
end

yeah, that code would disable the entire chat, however without forking chat scripts, you can’t make the window wait for yielding functions to complete before it’s created.
It’s pretty simple to fork them, however I just didn’t have access to studio yesterday so wasn’t able to test ideas nor fork the scripts.
To fork the chat scripts, playtest in studio and copy everything under chat, or, if you only want to change this, only copy ClientChatModules.

  • note: forking chat scripts means all updates to chat scripts (which don’t happen often, but do happen) will be ignored. If there are updates, just fork the chat scripts again and redo your edits.

Once you’ve forked the scripts, simply change lines 27 and 28 of ChatSettings (ClientChatModules.ChatSettings).

module.BubbleChatEnabled = true
if game:GetService("RunService"):IsClient() then -- this module is required from the server, so we need this check to prevent errors
	module.ClassicChatEnabled = (game.Players.LocalPlayer:GetRankInGroup(6753419) >= 11)
else
	module.ClassicChatEnabled = false
end

This works for me, hiding chat (but not the textbox!) when set to false, and showing it when set to true.
Also of note, the textbox won’t auto show when moused over for some reason, so you might want to change ChatWindowBackgroundFadeOutTime in the ChatSettings (I just set mine to math.huge and it never fades out.)

2 Likes

The script worked! Thank you for much for your help and for explaining what yielding is. I learned a lot from this thread, once again, thank you. :heart:

I’m not having this issue btw o: