Rainbow chat system messages with TextChatService

I need help making a part of a system message with a rainbow gradient using TextChatService. I saw this in Murder Mystery 2 Testing Server.
This is what I saw:


Thank you.

3 Likes

Creating a rainbow gradient effect in a text message can be achieved by using a series of colors that transition smoothly from one to the next. Here’s a basic example of how you can create a rainbow gradient effect:

-- Function to generate rainbow gradient text
local function rainbowText(text)
    local gradientColors = {
        Color3.fromRGB(255, 0, 0),     -- Red
        Color3.fromRGB(255, 127, 0),   -- Orange
        Color3.fromRGB(255, 255, 0),   -- Yellow
        Color3.fromRGB(0, 255, 0),     -- Green
        Color3.fromRGB(0, 0, 255),     -- Blue
        Color3.fromRGB(75, 0, 130),    -- Indigo
        Color3.fromRGB(148, 0, 211)    -- Violet
    }
    
    local textService = game:GetService("TextService")
    local gradientText = ""
    
    for i = 1, #text do
        local color = gradientColors[(i - 1) % #gradientColors + 1]
        local char = string.sub(text, i, i)
        
        gradientText = gradientText .. "<font color=\"rgb(".. color.R ..",".. color.G ..",".. color.B ..")\">" .. char .. "</font>"
    end
    
    return gradientText
end

-- Example usage:
local message = rainbowText("Hello, world!")

-- Output the message using TextChatService or other means
-- Example in Roblox:
local TextChatService = game:GetService("TextService")
TextChatService:Chat(message)

Explanation:

  1. Gradient Colors: We define an array gradientColors containing several Color3 values representing the colors of the rainbow (red, orange, yellow, green, blue, indigo, violet).

  2. rainbowText Function: This function takes a text string as input and generates HTML-like formatted text with a rainbow gradient effect.

    • It iterates through each character in the text string.
    • Assigns a color from gradientColors based on the index.
    • Constructs an HTML-like <font> tag with the RGB values of the color.
    • Concatenates each character and its corresponding <font> tag into gradientText.
  3. Example Usage:

    • Call rainbowText with your desired message ("Hello, world!" in this example).
    • Use TextChatService:Chat() or similar methods in your game engine to display or process the formatted message.

Note:

  • Ensure you have appropriate permissions and capabilities to use TextChatService or similar services in your environment.
  • Adjust the gradientColors array or add more colors for different effects or smoother gradients.
1 Like

Do I make a server script in ServerScriptService for that?

3 Likes

Server Script:

If you want the rainbow text generation to happen on the server and broadcast to all players:

  • Location: ServerScriptService or a ModuleScript required by a ServerScriptService script.
  • Reason: This ensures that all players receive the same message with rainbow text.
1 Like

Local Script:

If you want the rainbow text to be generated and displayed locally on each player’s screen:

  • Location: StarterGui, PlayerGui, or a LocalScript within a GuiObject (like a TextLabel).
  • Reason: This ensures that each player sees their own instance of the rainbow text.
1 Like

ModuleScript:

If you want to reuse the rainbow text generation function across multiple scripts:

  • Location: ReplicatedStorage as a ModuleScript.
  • Reason: This allows you to require the module in both server and client scripts for consistent rainbow text generation.
1 Like

It doesn’t work, but I followed all the steps

2 Likes

Where did you decide to place your script and what errors does it say on the output?

1 Like

I decided to put the code in a localscript and put it in StarterGui
It doesn’t output anything

1 Like
local StarterGui = game:GetService("StarterGui")
local TextService = game:GetService("TextService")

-- Function to generate rainbow gradient text
local function rainbowText(text)
    local gradientColors = {
        Color3.fromRGB(255, 0, 0),     -- Red
        Color3.fromRGB(255, 127, 0),   -- Orange
        Color3.fromRGB(255, 255, 0),   -- Yellow
        Color3.fromRGB(0, 255, 0),     -- Green
        Color3.fromRGB(0, 0, 255),     -- Blue
        Color3.fromRGB(75, 0, 130),    -- Indigo
        Color3.fromRGB(148, 0, 211)    -- Violet
    }
    
    local gradientText = ""
    
    for i = 1, #text do
        local color = gradientColors[(i - 1) % #gradientColors + 1]
        local char = string.sub(text, i, i)
        
        gradientText = gradientText .. "<font color=\"rgb(".. color.R ..",".. color.G ..",".. color.B ..")\">" .. char .. "</font>"
    end
    
    return gradientText
end

-- Example text to display
local exampleText = "Hello, world!"

-- Create a TextLabel
local label = Instance.new("TextLabel")
label.Name = "RainbowText"
label.Text = exampleText
label.Size = UDim2.new(1, 0, 1, 0)  -- Full-screen size
label.Position = UDim2.new(0, 0, 0, 0)  -- Top-left corner
label.BackgroundTransparency = 1  -- Transparent background
label.TextScaled = true  -- Scales text to fit the label
label.TextColor3 = Color3.new(1, 1, 1)  -- Default text color
label.Font = Enum.Font.SourceSansBold  -- Font style (optional)
label.Parent = StarterGui

-- Function to update label text with rainbow effect
local function updateRainbowText()
    label.Text = rainbowText(exampleText)
end

-- Call the update function periodically to animate the rainbow effect
while true do
    updateRainbowText()
    wait(0.1)  -- Adjust delay for speed of animation
end

How to Use:

  1. Copy the Entire Script:
    Copy the entire script provided above.

  2. Create a LocalScript in StarterGui:
    In Roblox Studio, open the place where you want to use this script. Right-click on StarterGui in the Explorer panel, hover over Insert Object, and select LocalScript.

  3. Paste the Script:
    Paste the script into the LocalScript you just created.

  4. Run the Game:
    Playtest the game. You should see a TextLabel covering the screen with the text “Hello, world!” animated in a rainbow gradient effect.

Notes:

  • The while true loop continuously updates the TextLabel text to create the animated rainbow effect.
  • Adjust the exampleText variable to change the text displayed with the rainbow effect.
  • You can adjust the animation speed by changing the wait time (wait(0.1) in this example).
  • This script runs entirely on the client side (local to each player), making it suitable for UI effects in games.
2 Likes

you are missing a frame in which you put the text label

2 Likes

Roblox Man Face Crying

what did i say… have i said something wrong?

i meant screengui, sorry… you have to put it in a screen gui