Text Chat
Utility that makes it easier to work with TextChatService
local TextChatService = game:GetService("TextChatService")
local textchat = require("textchat")
local grouper = require("grouper")
local STAFF_CHANNEL = Instance.new("TextChannel")
STAFF_CHANNEL.Parent = TextChatService
grouper.on_rank_changed(function(player, new_rank)
if new_rank >= 10 then
textchat.add_to_channel(player, STAFF_CHANNEL)
else
textchat.remove_from_channel(player, STAFF_CHANNEL)
end
end)
Methods
get_color
Gets the roblox chat color for a name, using the same algorithm roblox uses for generating player chat colors.
local color = textchat.get_color("kalrnlo") -- Color3.fromHex("6b327c")
color:Lerp(.5)
get_prefix
Creates a chat prefix from the given name and display_name. That will be colored using the color generated by get_color
from the name. Includes optional args such as,
is_verified
- indicating if a roblox verified icon should be appended to the prefix (default: false)include_name
- indicates if the name should be included in the prefix, and not just the display_name (default: false)ending
- the ending thats appended to the end (defualt: ": " )
local display_name = "kal"
local name = "kalrnlo"
-- <font color="#6b327c">kal</font>:
local prefix = textchat.get_prefix(display_name, name)
get_prefix_for_player
Same as get_prefix
except it autofills the args display
, name
, and is_verified
. With Player.DisplayName
, Player.Name
, Player.HasVerifiedBadge
local Players = game:GetService("Players")
-- <font color="#6b327c">kal</font>:
local prefix = textchat.get_prefix_for_player(Players.LocalPlayer)
get_color_for_player
Wrapper for get_color
that uses the players name to generate the color.
local Players = game:GetService("Players")
-- Color3.fromHex("6b327c")
local color = textchat.get_color_for_player(Players.LocalPlayer)
color:Lerp(.5)
remove_from_channel
Utility function for removing a player from a TextChannel
local TextChatService = game:GetService("TextChatService")
local grouper = require("grouper")
local STAFF_CHANNEL = Instance.new("TextChannel")
STAFF_CHANNEL.Parent = TextChatService
grouper.on_rank_changed(function(player, new_rank)
if new_rank < 10 then
textchat.remove_from_channel(player, STAFF_CHANNEL)
end
end)
add_to_channel
Utility function for adding a player to a TextChannel
, as TextChannel:AddUserAsync
is a bit of a pain to deal with and also acts weirdly sometimes if you add a user before chat has loaded for that player.
local TextChatService = game:GetService("TextChatService")
local grouper = require("grouper")
local STAFF_CHANNEL = Instance.new("TextChannel")
STAFF_CHANNEL.Parent = TextChatService
grouper.on_rank_changed(function(player, new_rank)
if new_rank >= 10 then
textchat.add_to_channel(player, STAFF_CHANNEL)
end
end)
set_mute
Sets if a player is muted in all TextChannels, if the channel
arg is provided it will only set the mute for the player in that channel.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
textchat.set_mute(player, true)
task.wait(5)
textchat.set_mute(player, false)
end)
is_muted
Returns a boolean indicating if a player is muted in all channels, if the channel
arg is provided it will only check if the player is muted in that specific channel.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
textchat.set_mute(player, true)
textchat.is_muted(player) -- true
end)