#textchatservice proximity and commands

465 messages · Page 1 of 1 (latest)

noble imp
#

I am using the proximity-chat script provided by roblox

https://devforum.roblox.com/t/textchatservice-new-chat-window-customization-and-delivery-apis/2054343

^In that post,

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local generalChannel : TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral

local function getPositionFromUserId(userId)
    local targetPlayer = Players:GetPlayerByUserId(userId)
    if targetPlayer then
        local targetCharacter = targetPlayer.Character
        if targetCharacter then
            return targetCharacter:GetPivot().Position
        end
    end

    -- return default position for example
    return Vector3.new(0, 0, 0)
end

generalChannel.ShouldDeliverCallback = function(textChatMessage: TextChatMessage, targetTextSource: TextSource)
    local sourcePos = getPositionFromUserId(textChatMessage.TextSource.UserId)
    local targetPos = getPositionFromUserId(targetTextSource.UserId)

    -- If the distance between players is less than 50, deliver the message.
    return (targetPos - sourcePos).magnitude < 50
end

Here is the server script, is it parented to server script service.

My question about this is, while the script works perfectly fine, as seen is this screenshot

#

How would I make it so the player names are changed, instead of it being their user names, it’ll be their character names they use based on my custom character creator

#

Talking about those names, how would I change that.
2. Secondly, I want to make multiple commands, such as /shout [Makes the players message yellow, and the proximity distance will be higher], /me [A roleplay action, the distance will be the same as the regular talking], and others as well. How would I do something like this.
A solution I came up with is…

1: Making multiple scripts, and each script is for each command, but I feel as if this would be way too inefficient.
Are there any other solutions? IS there anybody that can help me?

#

These would also be the commands, how would I implement them in the script, make them each different colors when messaged, and also proximity based as well?

delicate terrace
#

just substitute the name using gsub

noble imp
slim blade
noble imp
#

oh

slim blade
noble imp
#

the t just means "text"

#

its the image that roblox uses for the command objects

slim blade
#

oh ok

#

Did you fix the issue?

#

Also one thing you could do is have a dictionary with the key value of your command name and then assign to to a function

#

seperate the command in the message and then find it in the dictionary and run the command

#

lemme give an example

#

commands = {
  ["shout"] = function(paramaters)
    
  end;

  ["whisper"] = function(paramaters)
    
  end;
}

game.Players.Chatted:Connect(function(msg)
  local tokens = string.split(msg, " ")
  if string.sub(token[1], 1, 1) == "/" then -- replace with prefix you want
    local commandName = string.sub(token[1], 2, string.len(token[1]) -- get commands name
    local paramaters = table.remove(tokens, 1) -- removes command so we only send params
    if commands[commandName] then
      commands[commandName](paramaters)
    end
  end
end)
#

THere is likely amore effecient and optomized way but this should serve as a general idea on what to do

noble imp
noble imp
#

Using textchatservice, I am using the actual objects that listens itself if the command has been used using the .triggered event , and if it has, it'll do whatever.

slim blade
#

1: Making multiple scripts, and each script is for each command, but I feel as if this would be way too inefficient.
Are there any other solutions? IS there anybody that can help me?

well i mean just change it for your needs

#

check for .triggered instead

#

same concept just changing it around a bit

noble imp
#

yeah i tried that and it didnt rlly work

#

let me show u the scrip

#
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

local meCmd = TextChatService:WaitForChild("/meCommand")
local doCmd = TextChatService:WaitForChild("/doCommand")
local shoutCmd = TextChatService:WaitForChild("/sCommand")
local lowCommand = TextChatService:WaitForChild("/lCommand")
TextChatService.OnIncomingMessage = function(message)
    

    local properties = Instance.new("TextChatMessageProperties")
    
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    
    
    if message.TextSource then
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)

        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", Color3.fromRGB(255,255,255):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")

        -- Default is message.PrefixText and will just show the player's username.
        properties.PrefixText = playerCharacterName
    end

    return properties
end
#
meCmd.Triggered:Connect(function(plr, msg)
    local properties = Instance.new("TextChatMessageProperties")
    if plr then
        print("me cmd connects")
        
        local player = Players:GetPlayerByUserId(plr.UserId)


        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", Color3.fromRGB(87, 0, 131):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value)

        -- Default is message.PrefixText and will just show the player's username.
        properties.PrefixText = playerCharacterName
    end
    return properties
end)

#
doCmd.Triggered:Connect(function(plr, msg)
    local properties = Instance.new("TextChatMessageProperties")
    if plr then
        print("do cmd connects")
        
        local player = Players:GetPlayerByUserId(plr.UserId)


        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", Color3.fromRGB(87, 0, 131):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value)

        -- Default is message.PrefixText and will just show the player's username.
        properties.PrefixText = playerCharacterName
    end
    return properties
end)
#
lowCommand.Triggered:Connect(function(plr, msg)
    local properties = Instance.new("TextChatMessageProperties")
    if plr then
        print("low cmd connects")
        
        local player = Players:GetPlayerByUserId(plr.UserId)

        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", Color3.fromRGB(98, 98, 98):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value.. " whispers:")

        -- Default is message.PrefixText and will just show the player's username.
        properties.PrefixText = playerCharacterName
    end
    return properties

end)

#
shoutCmd.Triggered:Connect(function(plr, msg)
    local properties = Instance.new("TextChatMessageProperties")
    if plr then
        print("shout cmd connects")
        
        local player = Players:GetPlayerByUserId(plr.UserId)
        
        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", Color3.fromRGB(136, 136, 68):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value.. " shouts:")

        -- Default is message.PrefixText and will just show the player's username.
        properties.PrefixText = playerCharacterName
    end
    return properties
end)
#

all in one script (cant send the entire thing, discord is dumb)

#

no errors either 🤷‍♂️

jagged capeBOT
#

studio** You are now Level 7! **studio

noble imp
#

@slim blade

slim blade
#

whats the issue

#

oh

#

hm some print statements there and there maybe lmme check

#

do you know if there commands are being triggered firstly?

noble imp
#

yup, the print lines actually do connect

#

but no chat is even being done after i do the commands

#

however if i chat normally its fine

slim blade
#

alr lemme check documentation rq

#

is there an actual documentation for the commands themselves

#

foudn it

noble imp
#

yeah

#

but i dont undersatnd how i can implement it in my actual chat

slim blade
#

does it work for you and just not send for others by chance?

#

or just like no message for anyone at all

noble imp
#

no message whatsoever

#

however normal messages work fine

#

if that helps at all

#

commands just done

#

like not even in the bubble chat

#

hmmm

slim blade
#

why are you returning properties

#

first thing i would do is add some print statements throughout the command, maybe its stopping somewhere

noble imp
#

i returend them because i returned them when doing them with original messages

TextChatService.OnIncomingMessage = function(message)
    

    local properties = Instance.new("TextChatMessageProperties")
    
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    
    
    if message.TextSource then
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)

        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", Color3.fromRGB(255,255,255):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")

        -- Default is message.PrefixText and will just show the player's username.
        properties.PrefixText = playerCharacterName
    end

    return properties
end
#

i think the problem MIGHT Be

#

the way roblox actually handles the commands

slim blade
#
shoutCmd.Triggered:Connect(function(plr, msg)
    local properties = Instance.new("TextChatMessageProperties")
    if plr then
        print("shout cmd connects")
        
        local player = Players:GetPlayerByUserId(plr.UserId)
        print("player found")
        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", Color3.fromRGB(136, 136, 68):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value.. " shouts:")

        print("Check")

        -- Default is message.PrefixText and will just show the player's username.
        properties.PrefixText = playerCharacterName

        print("bam")
    end
    return properties
end)
noble imp
#

like it doesn't even show up in the bubble chat.

#

alright, ill try this.

slim blade
#

k one sec just tell me if it doesnt print all of them

#

should print ('bam')

noble imp
#

alright.

#

its stopping somewhere. @slim blade

#

wait im dubm

slim blade
#

send script with checks maybe

noble imp
#

ignore that

slim blade
#

nice avatar btw

noble imp
#

its actually not stopping

slim blade
#

k hm

noble imp
slim blade
#

those arent local scripts handling commands right

noble imp
#

i gotta add the clothes

noble imp
#

under starterplayerscripts

slim blade
#

all of them?

noble imp
#

yeah all of my commands are under that one script

slim blade
#

well this might be starting to make sense

noble imp
#

(not to read, just to show)

slim blade
#

maybe use this

noble imp
#

how so

slim blade
#

because i dont think your even sending the message

#

like after you intercept it

noble imp
#

yeah, see thats what i thought the problem was not gonna lie

slim blade
#

like the command evokes but you never send the message

#

because the clients just listening to the event

noble imp
#

i actually send it, but the command doesn't send my message into the chatwindow or bubble at all

slim blade
#

but doing nothing after that

noble imp
#

you explained it better

#

its just the way the chatcommands work

slim blade
#

can you show where u send it

noble imp
#

after you do a command, the chat wont send

slim blade
#

Well yeah its a command i guess, prob to make it more neat

#

So I guess send the message then

noble imp
#

yeah it actually does help

noble imp
slim blade
#

i think this

#

lemme send link

noble imp
#

i dont understand

slim blade
#

well alls your doing is listening for a command

#

but never sending a message

#

.Triggered is jsut an event

#

you shouldnt be returning anytthing

noble imp
#

yeah i understand that part, you explained it very well, but i dont know how to use "sendasync"

noble imp
slim blade
#

hm lemme try to make quick example

noble imp
#

ah

slim blade
#

yeah see

#

so it doesnt send a message so just use :SendAsync

noble imp
#

can you still make the example please

slim blade
#

alr

#

can i see your hierarchy

noble imp
#

sure

slim blade
#

you need a text channel object first, then create a local script and use SendAsync on the object, the default text channel is like this in hierarchy

noble imp
#

like this?

slim blade
#

no dont put commands in there

#

when you play, the game makes a default text channel

slim blade
#

so you wanna get a reference to the text channel object and use sendasync

noble imp
#

yeah i believe its there by default

slim blade
#

yep

#

now just do SendAsync()

#

and provide the message

#

as first paramter

#

now as long what you sending over isnt like a command like /kill noob, it should be handled like a regular message

noble imp
#
generalChannel:SendAsync(string.format("<font color='#%s'>%s</font>", Color3.fromRGB(136, 136, 68):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value.. " shouts:"))

#

like this?

#

its all one line btw

slim blade
#

yeah should work

#

as long string.format returns a string

noble imp
#

added the .. msg btw

slim blade
#

yep thats fine

noble imp
#

alright lets se

slim blade
#

make sure its a localscript

noble imp
#

mhm all in htere

slim blade
#

moment of truth

noble imp
#

IT WORKS BUT UH

slim blade
#

ok so its not formatting

#

does it even accept formatted strings

noble imp
#

and also the /s isnt even supposed to be there

noble imp
slim blade
noble imp
slim blade
#

no when commands sent

#

you remove it

noble imp
slim blade
noble imp
#

dang

slim blade
#

not like that

#

remove formatting

#

in the unfiltered text its probably including /S

#

to fix this do this

noble imp
#

i've removed string.format

#
generalChannel:SendAsync("<font color='#%s'>%s</font>", Color3.fromRGB(136, 136, 68):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value.. " shouts:" .. msg)
slim blade
#

no like dont format it at all

#

just include the part for message

noble imp
#

oh okay

#

like so?

slim blade
#

since the messages arent rich text apparently

slim blade
#

ima give scirpt to remove the command part out of message

noble imp
#

alright.

#

what in the

slim blade
#
local str = "/S noob you suck haha"
local _, endIndex = string.find(str, "%s")
local result = string.sub(str, endIndex + 1)
#

the result would be it without that /S

#

show what it sends now

noble imp
#

so would i send the result? through send async?

slim blade
#

yep

noble imp
#

alr lets see

slim blade
#

no wait

#

str should be equal to the message

#

so just replace str with the message

noble imp
#

like that

#

alright

slim blade
#

yeah or just remove str variable and pass i msg

#

in*

#

but that pretty much should work

noble imp
#

works!

slim blade
#

nice

noble imp
#

so i got ONE more question if ur up for it @slim blade ik i put u thru alot

slim blade
#

what is it

noble imp
#

alright so basically, each command should have its own this part

#

so shouts would be "eric armstrong shouts"

#

for the low command, "eric armstrong whispers" etc etc

#

with different colors as well

#

so my question is

slim blade
#

can i see your message handling script

noble imp
#
TextChatService.OnIncomingMessage = function(message)
    

    local properties = Instance.new("TextChatMessageProperties")
    
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    
    
    if message.TextSource then
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)

        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", Color3.fromRGB(255,255,255):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")

        -- Default is message.PrefixText and will just show the player's username.
        properties.PrefixText = playerCharacterName
    end

    return properties
end

```i
I handle the original message through this
#

so basically ANY message that passes through, is gonna hev that format on the playercharactername variable

slim blade
#

i see

noble imp
#

how would i change it so
it'll end up saying "shouts", "whisper", etc, and also have different colors

slim blade
#

i know why it was showing format

#

originally

#

so here this is just the way you want it to be by default right?

noble imp
slim blade
#

so just set that on the object in studio

#

and format on the command script instead

noble imp
slim blade
#

and format the string through using :SendAsync() on commands like before

#

and it should work

noble imp
#

yeah but it'll need the name part too

slim blade
#

what name part

#

oh

noble imp
#

"player.firstname.value, player.lastname.value"

#

thats how i get the playername

slim blade
#

you can get those from the client side as well

#

now one risk might be exploiters there tho

#

cant you just format it with the color, then just format the names on server

noble imp
slim blade
#

this would be easier if send async could have paramaters send throuh it

noble imp
#

so look

#

my chat has proximity in it aswell on the server

#

would i simply do it through there

#

ive never done chat coding before this is all new to me

#

kinda sucks that this service is new too, theres not many articles on it

slim blade
#

whats this

slim blade
noble imp
# slim blade whats this

proximity chat script, it means that you have to bea certain distance from a player in order to see their message from the chat

#

as you can see player2 cannot see player1s chat because theyre so far away

slim blade
#

alr i know what you can do

#

local TextChatMessage = game:GetService("TextService"):GetChatService("TextChat")
local message = "Hello, world!"
local color = Color3.fromRGB(255, 0, 0)  -- Example: Red color

-- Convert the color to a string representation
local colorString = string.format("#%02X%02X%02X", color.R * 255, color.G * 255, color.B * 255)

-- Create a metadata string with the color information
local metadata = string.format("Color:%s", colorString)

-- Send the message with metadata
TextChatMessage:SendAsync(message, metadata)
noble imp
#

on the server or client

#

and where in the script would i put it

slim blade
#

well your sending this stuff over the client heres the thing im trying to show yu

#

send async accepts meta data

noble imp
#

ohh

slim blade
#

so youcan send the color through there i guess is what im saying

#

or actually one thing you can do

#

esnetially you can send data through a string

#

and extract it from the string

#

lemme give example

noble imp
#

like so?

slim blade
#

one sec

noble imp
#

ok

slim blade
#

client

local color = Color3.fromRGB(255, 0, 0)  -- Example: Red color

-- Convert the color to a string representation
local colorString = string.format("%d,%d,%d", color.R * 255, color.G * 255, color.B * 255)

-- Send the message with the color string as metadata
TextChatMessage:SendAsync("Hello, world!", colorString)

server

game:GetService("TextService").TextChat.MessagePosted:Connect(function(message)
    -- Check if the message has metadata
    if message.Metadata then
        -- Extract the color string from the metadata
        local colorString = message.Metadata

        -- Split the color string into RGB values
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

        -- Convert the RGB values back into a Color3
        local color = Color3.new(tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255)

        -- Use the color value as desired
        print("Received color:", color)
    end
end)
#

obv change this for your needs

#

but this sould work

#

this would be how you send a color and get the color using the meta data param

noble imp
#

hmm it makes sense to me

#

lets see

slim blade
#

but wait try to format it

#

unless u wanna test first

#

to make sure ur getting color

#

yeh thats prob good idea do that firs

noble imp
#

yeah ill test it first

#

it doesnt give the color

jagged capeBOT
#

studio** You are now Level 8! **studio

slim blade
#

did you format using the color

#

and alos pass ina color

#

make sure to use format

noble imp
#

alright

#

using this like right?

#

testing 123 testing 123 gimmie a sec

slim blade
#

uh

#

no

#

your overcomplicating it

#

look here you already got the color variable

#

now just format the string using this color variable like u were before

noble imp
#

alright.

slim blade
#

show your code

#

for handler and for command

noble imp
#

its meant to be textchatservice right

slim blade
#

yes

noble imp
#

let me test now

#

stilll no

#
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local generalChannel : TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral

local meCmd = TextChatService:WaitForChild("/meCommand")

local function getPositionFromUserId(userId)
    local targetPlayer = Players:GetPlayerByUserId(userId)
    if targetPlayer then
        local targetCharacter = targetPlayer.Character
        if targetCharacter then
            return targetCharacter:GetPivot().Position
        end
    end

    -- return default position for example
    return Vector3.new(0, 0, 0)
end



generalChannel.ShouldDeliverCallback = function(textChatMessage: TextChatMessage, targetTextSource: TextSource)


    local Properties = Instance.new("TextChatMessageProperties")


    local sourcePos = getPositionFromUserId(textChatMessage.TextSource.UserId)
    local targetPos = getPositionFromUserId(targetTextSource.UserId)

    -- If the distance between players is less than 50, deliver the message.

    
    return (targetPos - sourcePos).magnitude < 50
end

game:GetService("TextChatService").TextChat.MessagePosted:Connect(function(message)
    -- Check if the message has metadata
    if message.Metadata then
        -- Extract the color string from the metadata
        local colorString = message.Metadata

        -- Split the color string into RGB values
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

        -- Convert the RGB values back into a Color3
        local color = Color3.new(tonumber(r) / 12, tonumber(g) / 12, tonumber(b) / 12)

        -- Use the color value as desired
        print("Received color:", color)
    end
end)
#

server^

slim blade
#

once again your not even formatting the text anymore

noble imp
#

client

slim blade
#

your just pritning it

noble imp
#

what do you mean?

slim blade
#

nowhere in here do you actually format the message

noble imp
#

oh wow

slim blade
#

your just pritning the color

noble imp
#

like this?

#

nevermind

slim blade
#

simple

noble imp
#

its not firing the print btw

#

even before i sendasync

slim blade
#

really cant do much if ur not sending ur code

noble imp
#
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local generalChannel : TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral

local meCmd = TextChatService:WaitForChild("/meCommand")

local function getPositionFromUserId(userId)
    local targetPlayer = Players:GetPlayerByUserId(userId)
    if targetPlayer then
        local targetCharacter = targetPlayer.Character
        if targetCharacter then
            return targetCharacter:GetPivot().Position
        end
    end

    -- return default position for example
    return Vector3.new(0, 0, 0)
end



generalChannel.ShouldDeliverCallback = function(textChatMessage: TextChatMessage, targetTextSource: TextSource)


    local Properties = Instance.new("TextChatMessageProperties")


    local sourcePos = getPositionFromUserId(textChatMessage.TextSource.UserId)
    local targetPos = getPositionFromUserId(targetTextSource.UserId)

    -- If the distance between players is less than 50, deliver the message.

    
    return (targetPos - sourcePos).magnitude < 50
end

game:GetService("TextChatService").TextChat.MessagePosted:Connect(function(message)
    -- Check if the message has metadata
    if message.Metadata then
        -- Extract the color string from the metadata
        local colorString = message.Metadata

        -- Split the color string into RGB values
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

        -- Convert the RGB values back into a Color3
        local color = Color3.new(tonumber(r) / 12, tonumber(g) / 12, tonumber(b) / 12)

        -- Use the color value as desired
        
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", Color3.fromRGB(255,255,255):ToHex(), player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")
        
        print("Received color:", color)
    end
end)    
slim blade
#

so what does the message show up as

noble imp
#

well i now have to define the player somehow

slim blade
#

i think your removing stuff rom your code when you shouldnt

slim blade
#

not sure what the confusion is atp

noble imp
slim blade
#

i mean

#

you did it alreayd

#

once again stop removing this you shouldnt

noble imp
#

testing again

#

its not formatting man

#
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local generalChannel : TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral




local function getPositionFromUserId(userId)
    local targetPlayer = Players:GetPlayerByUserId(userId)
    if targetPlayer then
        local targetCharacter = targetPlayer.Character
        if targetCharacter then
            return targetCharacter:GetPivot().Position
        end
    end

    -- return default position for example
    return Vector3.new(0, 0, 0)
end



generalChannel.ShouldDeliverCallback = function(textChatMessage: TextChatMessage, targetTextSource: TextSource)


    local Properties = Instance.new("TextChatMessageProperties")


    local sourcePos = getPositionFromUserId(textChatMessage.TextSource.UserId)
    local targetPos = getPositionFromUserId(targetTextSource.UserId)

    -- If the distance between players is less than 50, deliver the message.

    
    return (targetPos - sourcePos).magnitude < 50
end

game:GetService("TextChatService").TextChat.MessagePosted:Connect(function(message)
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    -- Check if the message has metadata
    if message.Metadata then
        -- Extract the color string from the metadata
        local colorString = message.Metadata

        -- Split the color string into RGB values
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

        -- Convert the RGB values back into a Color3
        local color = Color3.new(tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255)

        -- Use the color value as desired
        
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", color, player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")
        
        print("Received color:", color)
    end
end)    
#

once again, server script

#

local

slim blade
#

for loacl just send shout command

noble imp
#

so no formatting on the client?

slim blade
#

no

#

alls your doing on client is sending the color

#

and on server ur using the color

#

either way just send shout command

noble imp
#
shoutCmd.Triggered:Connect(function(plr, msg)
    local properties = Instance.new("TextChatMessageProperties")
    if plr then
        print("shout cmd connects")

        local player = Players:GetPlayerByUserId(plr.UserId)
        print("player found")
        
        local str = msg
        local _, endIndex = string.find(str, "%s")
        local result = string.sub(str, endIndex + 1)
        
    

        -- Send the message with metadata
        
        
        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        generalChannel:SendAsync(result)

        print("Check")

        -- Default is message.PrefixText and will just show the player's username.
        
        
    
        
        print("bam")
        end
    end)
slim blade
#

i dont need th rest

#

no what did you do

#

your not even sending the color now

noble imp
#

mane u just told me to just send the shout cmd 😭

slim blade
#

your not sending the color

#

i genuinely dont know what your struggling with your just reoving a bunch of stuff you need from your scripts

noble imp
#
shoutCmd.Triggered:Connect(function(plr, msg)
    local properties = Instance.new("TextChatMessageProperties")
    if plr then
        print("shout cmd connects")

        local player = Players:GetPlayerByUserId(plr.UserId)
        print("player found")
        
        local str = msg
        local _, endIndex = string.find(str, "%s")
        local result = string.sub(str, endIndex + 1)
        
        -- Convert the color to a string representation
        local colorString = string.format("#%02X%02X%02X", color.R * 255, color.G * 255, color.B * 255)

        -- Create a metadata string with the color information
        local metadata = string.format("Color:%s", colorString)

        -- Send the message with metadata
        
        
        -- This is assuming the name is stored in a stringValue in the player object. Change this to whatever you need.
        generalChannel:SendAsync(result, metadata)

        print("Check")

        -- Default is message.PrefixText and will just show the player's username.
        
        
    
        
        print("bam")
        end
    end)
slim blade
#

now on server send me what u got rn

noble imp
#
game:GetService("TextChatService").TextChat.MessagePosted:Connect(function(message)
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    -- Check if the message has metadata
    if message.Metadata then
        -- Extract the color string from the metadata
        local colorString = message.Metadata

        -- Split the color string into RGB values
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

        -- Convert the RGB values back into a Color3
        local color = Color3.new(tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255)

        -- Use the color value as desired
        
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", color, player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")
        
        print("Received color:", color)
    end
end)    
slim blade
#

and its still white'

#

?

noble imp
#

yeah.

#

like what bro

slim blade
#

print the color strng and meta dta

slim blade
#

where ur getting the error from

noble imp
#

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local generalChannel : TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral




local function getPositionFromUserId(userId)
    local targetPlayer = Players:GetPlayerByUserId(userId)
    if targetPlayer then
        local targetCharacter = targetPlayer.Character
        if targetCharacter then
            return targetCharacter:GetPivot().Position
        end
    end

    -- return default position for example
    return Vector3.new(0, 0, 0)
end



generalChannel.ShouldDeliverCallback = function(textChatMessage: TextChatMessage, targetTextSource: TextSource)


    local Properties = Instance.new("TextChatMessageProperties")


    local sourcePos = getPositionFromUserId(textChatMessage.TextSource.UserId)
    local targetPos = getPositionFromUserId(targetTextSource.UserId)

    -- If the distance between players is less than 50, deliver the message.

    
    return (targetPos - sourcePos).magnitude < 50
end

game:GetService("TextChatService").TextChat.MessagePosted:Connect(function(message)
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    -- Check if the message has metadata
    if message.Metadata then
        -- Extract the color string from the metadata
        local colorString = message.Metadata

        -- Split the color string into RGB values
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

        -- Convert the RGB values back into a Color3
        local color = Color3.new(tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255)

        -- Use the color value as desired
        
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", color, player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")
        
        print("Received color:", color)
    end
end)    
#

game:GetService("TextChatService").TextChat.MessagePosted:Connect(function(message)
#

this line

#

TextChat is not a valid member of TextChatService "TextChatService" - Server - ProximityChat:38

#

serverside

#

thats why it was sending because of the client, but not formatting because of the server

slim blade
#

its self explanatory

#

text chat isnt in there

noble imp
#

yeah

slim blade
#

so then what is even text chat

noble imp
#

literally no clue

slim blade
#

just remove .TextChat

noble imp
#

i mean u kinda gave me that line

slim blade
#

idk what your confused about

#

I never told you that but go ahead and say that

noble imp
#

mane..

slim blade
#

Its boiler template

#

you take what you need and modify

#

dont absoloutely steal it

noble imp
#

alright hold on

slim blade
#

idc im not arguing about this tell me what happens now that errors gone

noble imp
#

OH I SEE HTE PROBLEM

slim blade
#

what

noble imp
#

"messagerecieved" is the correct event

#

its EXACTLY what im looking for

slim blade
#

try it

noble imp
#

"fires whenever sendasync is sent from the client"

#

lets see

#

doesnt work let me see if anything even prints.

slim blade
#

lemme repeat this print the color

#

on the server

noble imp
#

alright im doing that

#
TextChatService.MessageReceived:Connect(function(message)
    print("message has been reicicved")
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    print("Player has been found")
    -- Check if the message has metadata
    if message.Metadata then
        print("metadata has been found")
        -- Extract the color string from the metadata
        local colorString = message.Metadata

        -- Split the color string into RGB values
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

        -- Convert the RGB values back into a Color3
        local color = Color3.new(tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255)
        print(color)

        -- Use the color value as desired
        
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", color, player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")
        
        print("Received color:", color)
    end
end)
slim blade
#

i need to know whwat it prints

#

not the code

noble imp
#

right

#

nothing on the server is printing

slim blade
noble imp
#

yeah i just caught that

slim blade
#

also i know why

#

your not sending the meta data

#

on client

noble imp
#

i am sir

slim blade
#

show?

#

k add an else statement

#

on server

#

for if metadata

noble imp
#

mhm

slim blade
#

actually one sec

#

add meta data paramater, and do if metadata instead of message.Metadata

noble imp
#

mhm

#
TextChatService.MessageReceived:Connect(function(message)
    local properties = Instance.new("TextChatMessageProperties")
    print("message has been reicicved")
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    print("Player has been found")
    -- Check if the message has metadata
    if message then
        print("metadata has been found")
        -- Extract the color string from the metadata
        local colorString = message.Metadata

        -- Split the color string into RGB values
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

        -- Convert the RGB values back into a Color3
        local color = Color3.new(tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255)
        print(color)

        -- Use the color value as desired
        
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", color, player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")
        
        properties.PrefixText = playerCharacterName
        print("Received color:", color)
        
    else
        print("Not found metadata")
        
        
    end
end)
``` includes all the recent changes
slim blade
#

no i dont know how that just blew over your head

#

i suggest you sleep

#

add a paramater called metadata

#

to the event

#

and do if metadata

#

not if message

#

TextChatService.MessageReceived:Connect(function(message, metadata)
    local properties = Instance.new("TextChatMessageProperties")
    print("message has been reicicved")
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    print("Player has been found")
    -- Check if the message has metadata
    if metadata then
        print("metadata has been found")
        -- Extract the color string from the metadata
        local colorString = metadata

        -- Split the color string into RGB values
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

        -- Convert the RGB values back into a Color3
        local color = Color3.new(tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255)
        print(color)

        -- Use the color value as desired
        
        local playerCharacterName = string.format("<font color='#%s'>%s</font>", color, player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")
        
        properties.PrefixText = playerCharacterName
        print("Received color:", color)
        
    else
        print("Not found metadata")
        
        
    end
end)
noble imp
#

oh my god

slim blade
#

TextChatService.MessageReceived:Connect(function(message, metadata)
local properties = Instance.new("TextChatMessageProperties")
print("message has been reicicved")
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
print("Player has been found")
-- Check if the message has metadata
if metadata then
print("metadata has been found")
-- Extract the color string from the metadata
local colorString = metadata

    -- Split the color string into RGB values
    local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

    -- Convert the RGB values back into a Color3
    local color = Color3.new(tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255)
    print(color)

    -- Use the color value as desired
    
    local playerCharacterName = string.format("<font color='#%s'>%s</font>", color, player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")
    
    properties.PrefixText = playerCharacterName
    print("Received color:", color)
    
else
    print("Not found metadata")
    
    
end

end)

#

here

noble imp
slim blade
#

k test it

noble imp
#

k

#

the prints on the server arent firing

#

uhm, could it be because of the code above i

slim blade
#

can you go back to using message posted

#

becuz it worked fine

noble imp
slim blade
#

k

noble imp
slim blade
#

using OnIncomingMessage like before

noble imp
#

k

#

onincoming message is a function

slim blade
#

just use it

#

it is not a fucking

noble imp
slim blade
#

function*

#

no

#

.OnIncomingMessage = function()

#

TextChatService.OnIncomingMessage = function()

end)

#

its like that

noble imp
slim blade
#

now try it

noble imp
#

yeah like

#

nothing prints serverside

#

im probably gonna have to do this an entirely different way im ngl

slim blade
#

at this point just send the entire script

slim blade
noble imp
#

alright

#
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local generalChannel : TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral




local function getPositionFromUserId(userId)
    local targetPlayer = Players:GetPlayerByUserId(userId)
    if targetPlayer then
        local targetCharacter = targetPlayer.Character
        if targetCharacter then
            return targetCharacter:GetPivot().Position
        end
    end

    

    return Vector3.new(0, 0, 0)
end



generalChannel.ShouldDeliverCallback = function(textChatMessage: TextChatMessage, targetTextSource: TextSource)


    local Properties = Instance.new("TextChatMessageProperties")


    local sourcePos = getPositionFromUserId(textChatMessage.TextSource.UserId)
    local targetPos = getPositionFromUserId(targetTextSource.UserId)

    

    
    return (targetPos - sourcePos).magnitude < 50
end

TextChatService.OnIncomingMessage = function(message, metadata)
    local properties = Instance.new("TextChatMessageProperties")
    print("message has been reicicved")
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    print("Player has been found")
    
    if metadata then
        print("metadata has been found")
    
        local colorString = metadata

        
        local r, g, b = colorString:match("(%d+),(%d+),(%d+)")

    
        local color = Color3.new(tonumber(r) / 255, tonumber(g) / 255, tonumber(b) / 255)
        print(color)

        

        local playerCharacterName = string.format("<font color='#%s'>%s</font>", color, player.PlayerStatsFolder.FirstName.Value .. " " .. player.PlayerStatsFolder.LastName.Value .. " says:")

        properties.PrefixText = playerCharacterName
        print("Received color:", color)

    else
        print("Not found metadata")


    end
end
#

the ENTIRE serverscript

#

not a line missing, not a single error

slim blade
#

know what your probably gonna have to do this an different way

#

your own message handling and just posting the messages onto there

noble imp
slim blade
#

anyways im too tired i wish u luck cuz this shit idk sometimes u just gotta remake somethign

#

but it shouldnt take long tbh

noble imp
#

thanks man, thanks for the help

#

i appreciate it fr

slim blade
#

tbh just look at a tutorial or learn more about it first before u completely remake it

noble imp
#

yeah i will

slim blade
#

we could be missing something entirely

#

but yeah np cya

noble imp
#

thx bro