Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Chat filter for Custom GuideChats?

Hello, i want to add filter chat for Safety of the game, but i don't know how to create a filter for the chat.

Anybody able can help me on this?

print("Darkness 2 chat system initializing")
local Utils = assert(LoadLibrary("RbxUtility"))
chat10s = 10

while not _G["GameDatabase"] do wait() end
while not _G["GameDatabase"].ready do wait() end

gamemain = game.Workspace.GameMain
gamedata = gamemain.GameData
ing = gamedata.InGame
gr = gamedata.GameRunning
endt = gamedata.EndType

vl1 = gamemain.Chat1
vl2 = gamemain.Chat2

function pmode(nm)
	local fs = ing:findFirstChild(nm)
	if fs ~= nil then
		local al = fs:findFirstChild("Alive")
		if al ~= nil then
			if not al:IsA("BoolValue") then return 0 end
			if al.Value and endt.Value == "" then
				if fs:findFirstChild("Shadow") ~= nil then
					return 2
				else
					return 1
				end
			end
		end
	end
	return 0
end

ch_public = {{}, {}, {}, {}, {}, {}}
ch_game = {{}, {}, {}, {}, {}, {}}
function addval(arr, vl)
	for i = 1, #arr do
		arr[i] = arr[i + 1]
	end
	arr[6] = vl
end

game.Players.PlayerAdded:connect(function(newPlayer)
	local chat_amm = chat10s
	while _G["GameDatabase"].pinfo[newPlayer.Name] == nil do
		wait()
	end
	while wait() do
		if _G["GameDatabase"].pinfo[newPlayer.Name] == nil then return end
		if _G["GameDatabase"].pinfo[newPlayer.Name].ready then
			break
		end
	end
	newPlayer.Chatted:connect(function(msg)
		if string.sub(msg, 1, 2) == "/e" then return end
		if chat_amm == 0 then return end
		chat_amm = chat_amm - 1
		
		local pm = pmode(newPlayer.Name)
		if pm == 0 then
			addval(ch_public, {false, newPlayer.Name, msg})
			vl1.Value = Utils.EncodeJSON(ch_public)
		elseif pm == 1 then
			addval(ch_public, {true, newPlayer.Name, msg})
			addval(ch_game, {true, newPlayer.Name, msg})
			vl1.Value = Utils.EncodeJSON(ch_public)
			vl2.Value = Utils.EncodeJSON(ch_game)
		end
		
		wait(10)
		chat_amm = chat_amm + 1
	end)
end)

gr.Changed:connect(function()
	if gr.Value == true then return end
	ch_game = {{}, {}, {}, {}, {}, {}}
	vl2.Value = Utils.EncodeJSON(ch_game)
end)
wait(0.6)

gamemain = game.Workspace.GameMain
gamedata = gamemain.GameData
ing = gamedata.InGame

ch = gamemain.Chat1

local Utils = assert(LoadLibrary("RbxUtility"))
local player = game.Players.LocalPlayer
local hum = player.Character.Humanoid

local nametag = Instance.new("TextLabel")
nametag.BackgroundTransparency = 1
nametag.BorderSizePixel = 0
nametag.FontSize = "Size18"
nametag.Font = "Arial"
nametag.TextXAlignment = "Left"
nametag.ZIndex = 8

local cont = Instance.new("TextLabel")
cont.BackgroundTransparency = 1
cont.BorderSizePixel = 0
cont.FontSize = "Size18"
cont.Font = "Arial"
cont.TextXAlignment = "Left"
cont.TextColor3 = Color3.new(0.933, 0.933, 0.933)
cont.TextStrokeTransparency = 0.7
cont.Position = UDim2.new(1, 0, 0, 0)
cont.Size = UDim2.new(0, 0, 1, 0)
cont.ZIndex = 8


local cf = script.Parent.ChatFrame
hum.Died:connect(function()
	cf.Visible = false
end)

local clr = script:findFirstChild("bnd")
if clr then clr:remove() end
local bndc = nametag:clone()
bndc.Name = "bnd"
bndc.Visible = false
bndc.Parent = script
function getbounds(txt)
	bndc.Text = txt
	return bndc.TextBounds.x
end

function DrawChat(inf)
	cf:ClearAllChildren()
	if inf == "" then return end
	local list = Utils.DecodeJSON(inf)
	for i, v in ipairs(list) do
		if v[1] ~= nil then
			local ntg = nametag:clone()
			ntg.Text = v[2] .. ":"
			ntg.Size = UDim2.new(0, getbounds(ntg.Text) + 4, 1/6, 0)
			ntg.Position = UDim2.new(0, 0, 1/6 * (i-1), 0)
			if v[1] then
				ntg.TextColor3 = Color3.new(1, 0, 0)
			else
				ntg.TextColor3 = Color3.new(0.39, 0.39, 0.39)
			end
			local nc = cont:clone()
			nc.Text = v[3]
			nc.Parent = ntg
			ntg.Parent = cf
		end
	end
end

local con = ch.Changed:connect(function() DrawChat(ch.Value) end)
DrawChat(ch.Value)

ing.ChildAdded:connect(function(obj)
	if obj.Name == player.Name then
		con:disconnect()
		cf.Visible = false
	end
end)

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.