String.len suddenly broke my script and i dont know how to revert it

Hi. I’m currently making a chat system, however when I added string.len it entirely broke my script and it doesnt work now. Even when i reverted to a old version of the script, it wouldnt work. How would I fix it

Server Script

local chatGui = script.ChatGui
plrs.PlayerAdded:Connect(function(a)
	local plrGui = a.PlayerGui
	chatGui.Parent = plrGui
	local chosen = math.random(1, #chatColors)
	local color = chatColors[chosen]
	event.OnServerEvent:Connect(function(plr,msg)
		local filteredMsg = chatService.filterText(plr,msg)
		local messageTxt = templateMessage:Clone()
		messageTxt.Parent = chatGui.ChatFrame
		messageTxt.Text = "<font color=\"#"..color.."\">"..plr.DisplayName..': '.."</font>"..filteredMsg
		
		chatService.TweenMessage(messageTxt)
		
	end)
end)

this is the script before I added string.len

Put your chatgui into StarterGui and don’t put server events into PlayerAdded because it will create multiple connections making the same code run more than once. Here is a fixed version of your code:

-- Server
local PlayersService = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")

local ChatEvent = ReplicatedStorage.Chat -- path to remote

local ChatColours = {Color3.new(1, 0, 0), Color3.new(0, 1, 0), Color3.new(0, 0, 1)} -- example colours
local PlayerColours = {}

PlayersService.PlayerAdded:Connect(function(Player)
    PlayerColours[Player.UserId] = ChatColours[math.random(1, #ChatColours)]
end)

ChatEvent.OnServerEvent:Connect(function(Player, Message)
    local FilteredMessage
    local Success = pcall(function()
        FilteredMessage = TextService:FilterStringAsync(Message, Player.UserId)
    end)

    if Success then
        ChatEvent:FireAllClients(Player.DisplayName, Message, PlayerColours[Player.UserId])
    end
end)

-- Client

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local UI = script.Parent
local ChatEvent = ReplicatedStorage.Chat -- path to remote

local function ConvertColor3(Colour)
    local R, G, B = Colour.R * 255, Colour.G * 255, Colour.B * 255

    return `rgb({math.round(R)}, {math.round(G)}, {math.round(B)});`
end

ChatEvent.OnClientEvent:Connect(function(DisplayName, Message, Colour)
    local Message = UI.TemplateMessage:Clone() -- path to template message
    Message.Parent = UI
    Message.Text = `<font color="{ConvertColor3(Colour)}">{DisplayName}: </font>{Message}`
    Message.Visible = true

    -- tween here
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.