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)
_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:
LocalPlayer.Chats
with contents.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.