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
According to the Wiki, the correct code is :GetRankInGroup, which is exactly what I’m using, and not :GetRoleInGroup… 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
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
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
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 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.
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.
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:
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
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…
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.)