Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Custom Chat issues?

Asked by
Bman8765 270 Moderation Voter
10 years ago

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)
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. TurboFusion 1821 — 10y
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 Bman8765 270 — 10y

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

_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.

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! Bman8765 270 — 10y
Ad

Answer this question