CustomChatGui - Not returning anything

I’m currently making a custom chatGui, however everytime I send a message nothing is sent or returned. How do I fix this?

Main Code

local resources = script:WaitForChild("Resources")
local players = game:GetService("Players")
local textService = game:GetService("TextService")

if not resources:FindFirstChild("kiAdminChat") then
	return
end

local function filterString(plr, toFilter)
	if toFilter and toFilter ~= "" then
		local success, filteredText = pcall(function()
			return textService:FilterStringAsync(toFilter, plr.UserId)
		end)

		if success then
			return filteredText
		end
	end
	return ""
end

local function sendServer(fromPlayer, message)
	if not message or type(message) ~= "string" or message == "" then return end

	for _, v in pairs(players:GetPlayers()) do
		if v.PlayerGui:FindFirstChild("kiAdminChat") then
			local gui = v.PlayerGui.kiAdminChat
			local chatList = gui.BaseClip.Inner.ChatsList

			if fromPlayer == nil then
				local template = gui.BaseClip.Inner.ChatsList.ServerTemplate:Clone()
				template.Text = tostring(message)
				template.Parent = chatList
			else
				local template = gui.BaseClip.Inner.ChatsList.MsgTemplate:Clone()
				template.UserIcon.Image = players:GetUserThumbnailAsync(fromPlayer.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size48x48)
				template.FromUser.Text = "@" .. fromPlayer.Name
				template.UserMessage.Text = tostring(message)
				template.Parent = chatList
			end
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	sendServer(nil, plr.Name .. " joined the server")

	local mutedData = Instance.new("BoolValue")
	mutedData.Name = "isMuted"
	mutedData.Value = false
	mutedData.Parent = plr

	local chatClone = resources.kiAdminChat:Clone()
	chatClone.Parent = plr:FindFirstChild("PlayerGui") or plr:WaitForChild("PlayerGui")

	chatClone.BaseClip.Submit.Interaction.MouseButton1Click:Connect(function()
		local inputBox = chatClone.BaseClip.Chat.TextInput
		local filteredMessage = filterString(plr, inputBox.Text)

		if filteredMessage and filteredMessage ~= "" then
			sendServer(plr, filteredMessage)
			inputBox.Text = ""
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	sendServer(nil, plr.Name .. " left the server")
end)

File
kiAdminChat.rbxm (25.1 KB)

Resolved:

local function filterString(player, text)
	local userId = player.UserId

	local success, filteredResult = pcall(function()
		local textFilterResult = textService:FilterStringAsync(text, userId)
		return textFilterResult:GetNonChatStringForBroadcastAsync()
	end)

	if success and filteredResult then
		return filteredResult
	end
end

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