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

Custom Chat issues?

I'm creating a custom chat and I'm having lots of issues, for starters the chat messages is not showing up for all the players. I just don't really know how I should do this which is why I was wondering if someone more experience with lua than me could improve on what I have already made

The Current code, found in a localscript in startergui:

repeat wait() until game.Players.LocalPlayer
wait(1)
local StarterGui = game:GetService('StarterGui')
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
---------------------------------------------------------------------------
--Variables
---------------------------------------------------------------------------
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
_G.moving = false
---------------------------------------------------------------------------
--Functions
---------------------------------------------------------------------------
function createChatLine()
	local textlabel = Instance.new("TextLabel")
	textlabel.BackgroundTransparency = 1
	textlabel.TextXAlignment = "Left"
	textlabel.Size = UDim2.new(1,0,.1,0)
	textlabel.Position = UDim2.new(0,0,0.76,0)
	textlabel.Name = "chatbar"
	return textlabel
end
---------------------------------------------------------------------------
--Global Functions
---------------------------------------------------------------------------

function _G.addMessage(player, chat)
	if (_G.moving == true) then
		repeat wait() until _G.moving == false
	end
	_G.moving = true
	print(_G.moving)
	for _, chatbars in pairs (script.Parent:GetChildren()) do
		if (chatbars.ClassName == "TextLabel") then
			chatbars:TweenPosition(UDim2.new(0,0,chatbars.Position.Y.Scale-.1,0), "Out", "Quad", .5, true)
			wait()		
		end
	end
	local chatbar = createChatLine()
	chatbar.Parent = script.Parent
	chatbar.Text = player.Name .. ": " .. chat
	script.Parent.ChatBar.Text = "Click Here to Chat"
	_G.moving = false
end

---------------------------------------------------------------------------
--Events
---------------------------------------------------------------------------
Mouse.KeyDown:connect(function(Key)
	if (Key == string.char(13)) then
		_G.addMessage(Player, script.Parent.ChatBar.Text)
	end
end)

2 comments

0

First try debugging it. Put print statements at certain areas to detect if they're running. Check the gui's to make sure the label is not just hidden. Then if all else fails, get back to us.

0

It's running fine but my main problem is what is a proper way to send a message to multiple people with my global function for creating a message. The global function is suppose to be called for everyone but it is not

1 answer

✓ Accepted answer

_G will not be shared between different LocalScripts. It's local to each client.

A RemoteEvent may be the best option. Otherwise, similar things like inserting labeled StringValues into some shared place (e.g., an object in the Workspace or Lighting, etc)


With FilteringEnabled, you could use a scheme that looks like this:

  • Say a message: Tell server to add a StringValue to LocalPlayer.Chats with contents
  • All LocalScripts look for ChildAdded events on all players' .Chats folder, and remove any new children, displaying them. (Removing will only be done for this client, so everyone will see)

There are probably lots of other ways to accomplish this, too.

1 comment

0

I think I'm gonna try multiple ones and see which one is best for me. Thanks, if you never informed me of my options I probably would have never done it that way!

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