Why Doesn't My Custom Chat Script Work?

I am remaking the chat, there is not a single error, and it still does not work for some odd reason. I have tried so many things. The code seems to get passed line 18 - 26, but it never shows up past that for some reason. If anyone has information / a solution on why this is happening, please reply.

UserInputService = game:GetService("UserInputService")
event = game.ReplicatedStorage:WaitForChild("PlayerChatted")

function strip(s)
	return (s:gsub('^%s*(.-)%s*$', '%1'))
end

UserInputService.InputEnded:Connect(function(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.Slash then
				script.Parent:CaptureFocus()
			end
		end
	end
end)

script.Parent.FocusLost:Connect(function(enter)
	if enter then
		local trimmed = strip(script.Parent.Text)
		if trimmed ~= '' then
			event:FireServer(trimmed)
		end
		script.Parent.Text = ''
	end
end)

event.OnClientEvent:Connect(function(filtered)
	local textMsg = script.Parent.Parent.Parent.MessageDefault.TextMessage:Clone()

	textMsg.Parent = script.Parent.Parent.Parent.MessageGridLayout
	textMsg.PlayerName.Text = "N/A"
	textMsg.PlayerMessage.Text = "filtered"
end)

Thanks For Reading!
-Peter :slight_smile:

1 Like

Is no one going to reply… Bruh

Could you provide the server script as well, if possible?

local UserInputService = game:GetService("UserInputService")
local event = game.ReplicatedStorage:WaitForChild("PlayerChatted")

function strip(s)
	return (s:gsub('^%s*(.-)%s*$', '%1'))
end

UserInputService.InputEnded:Connect(function(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.Slash then
				script.Parent:CaptureFocus()
			end
		end
	end
end)

script.Parent.FocusLost:Connect(function(enter)
	if enter then
		local trimmed = strip(script.Parent.Text)
		if trimmed ~= '' then
			event:FireServer(trimmed)
		end
		script.Parent.Text = ''
	end
end)

event.OnClientEvent:Connect(function(filtered)
	local textMsg = script.Parent.Parent.Parent.MessageDefault.TextMessage:Clone()

	textMsg.Parent = script.Parent.Parent.Parent.MessageGridLayout
	textMsg.PlayerName.Text = "N/A"
	textMsg.PlayerMessage.Text = filtered
end)

I have found a solution myself, but thanks for helping!