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

Custom Chat GUI is making all chat say instance?

The ServerLog Returns anything a player says as Instance, and only updates the Chat GUI Once. I also have a RemoteEvent in ReplicatedStorage called CombadgeEvent, ServerScriptService is a script, Chat GUI is a localScript

ServerScriptService Script.

game.ReplicatedStorage.CombadgeEvent.OnServerEvent:connect(function(sender, msg)
	local filteredmessage = game.Chat:FilterStringForBroadcast(msg, sender)
	print(sender.Name..' Said: '..filteredmessage)
	game.ReplicatedStorage.CombadgeEvent:FireAllClients(sender, filteredmessage)
end)

Chat GUI Script

local channels = script.Parent.Channels
local data = workspace.CombadgeSystem
local channel = script.Parent.Frequency
local on = script.Parent.On

local player = game.Players.LocalPlayer
local MACO = 1045203
local Temporal = 983872
local Starfleet = 947351

function transmit(sender, message)
	data[channel.Value].Line1.Value = data[channel.Value].Line2.Value
	data[channel.Value].Line2.Value = data[channel.Value].Line3.Value
	data[channel.Value].Line3.Value = data[channel.Value].Line4.Value
	data[channel.Value].Line4.Value = data[channel.Value].Line5.Value
	data[channel.Value].Line5.Value = data[channel.Value].Line6.Value
	data[channel.Value].Line6.Value = data[channel.Value].Line7.Value
	data[channel.Value].Line7.Value = " "..script.Parent.Parent.Parent.Name..":"..message
end 

function update(channel)
	script.Parent.Alert:Play()  
	channels[channel].Line1.Text = data[channel].Line1.Value
	channels[channel].Line2.Text = data[channel].Line2.Value
	channels[channel].Line3.Text = data[channel].Line3.Value
	channels[channel].Line4.Text = data[channel].Line4.Value
	channels[channel].Line5.Text = data[channel].Line5.Value
	channels[channel].Line6.Text = data[channel].Line6.Value
	channels[channel].Line7.Text = data[channel].Line7.Value
end

game.ReplicatedStorage.CombadgeEvent.OnClientEvent:connect(transmit)

function power(message)
	if string.find(message,"!on") == nil then
		script.Parent.EquipSound:Play()
		on.Value = false
		channels.MACO.Title.Power.BackgroundColor3 = Color3.new(1,0,0)
		channels.Starfleet.Title.Power.BackgroundColor3 = Color3.new(1,0,0)
		channels.Temporal.Title.Power.BackgroundColor3 = Color3.new(1,0,0)
	else
		on.Value = true 
		channels.MACO.Title.Power.BackgroundColor3 = Color3.new(0,1,0)
		channels.Starfleet.Title.Power.BackgroundColor3 = Color3.new(0,1,0)
		channels.Temporal.Title.Power.BackgroundColor3 = Color3.new(0,1,0)
	end
end

function toggle(message)
	if string.find(message, "maco") ~= nil and player:IsInGroup(MACO) then
		channel.Value = "MACO"
		channels.Temporal.Visible = false
		channels.MACO.Visible = true
		channels.Starfleet.Visible = false      
	elseif string.find(message, "starfleet") ~= nil then
		channel.Value = "Starfleet" 
		channels.Temporal.Visible = false
		channels.MACO.Visible = false
		channels.Starfleet.Visible = true   
	elseif string.find(message, "temporal") ~= nil and player:IsInGroup(Temporal) then
		channel.Value = "Temporal"
		channels.Temporal.Visible = true
		channels.MACO.Visible = false
		channels.Starfleet.Visible = false      
	end
end

script.Parent.Parent.Parent.Chatted:connect(function(message)
	local MESSAGE = string.lower(message)
	if on.Value == true and string.find(MESSAGE, "!on") == nil and string.find(MESSAGE, "!off") == nil and string.find(MESSAGE, "!channel") == nil 	then
		game.ReplicatedStorage.CombadgeEvent:FireServer(player, message)
	elseif string.find(MESSAGE, "!on") ~= nil or string.find(MESSAGE, "!off") ~= nil then
		power(MESSAGE)
	elseif string.find(MESSAGE, "!channel") ~= nil then
		toggle(MESSAGE)         
	end
end)

data.Starfleet.Line7.Changed:connect(function() update("Starfleet") end)
data.MACO.Line7.Changed:connect(function() update("MACO") end)
data.Temporal.Line7.Changed:connect(function() update("Temporal") end)
channels.MACO.Title.Power.MouseButton1Click:connect(function() if on.Value == false then power("!on") else power("!off") end end)
channels.Starfleet.Title.Power.MouseButton1Click:connect(function() if on.Value == false then power("!on") else power("!off") end end)
channels.Temporal.Title.Power.MouseButton1Click:connect(function() if on.Value == false then power("!on") else power("!off") end end)
channels.StarfleetToggle.MouseButton1Click:connect(function() toggle("starfleet") end)
channels.MACOToggle.MouseButton1Click:connect(function() toggle("maco") end)
channels.TemporalToggle.MouseButton1Click:connect(function() toggle("temporal") end)

1 answer

This code (the gui code) is very inefficient, you can just have a table with the chat messages, then every time it receives the event it updates the table then the gui, rather than having a bunch of string values (or whatever they are). For example

So you would start off with the event:

game.ReplicatedStorage.CombadgeEvent.OnClientEvent:connect(update)

And you would need to make the table (and reference the gui)

local chatmessages = {}
local gui = script.Parent --Change this to where the gui is relative to your script

And you could now make the update function

function update(sender,message)
	table.insert(chatmessages,{sender.Name,message})
	--removes them
	for _,c in pairs(gui:GetChildren()) do
		if c.Name == "TextLabel" then
			c:Destroy()
		end
	end
	--add the text labels here
end

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