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

Help with FilteringEnabled/Chat gui?

Asked by 10 years ago

Hello guys I'm back, this time with a slightly longer question, I am trying to make a filtering enabled chat gui but am having an issue. The message is meant to be made locally, then through a remote-event is cloned onto everyone's client other than the senders, here is the code:

Local code: (creates gui for the sender, successfully moves all other messages up one)

player.Chatted:connect(function(message)
    local PG  = player:WaitForChild("PlayerGui")
    repeat wait() until PG:FindFirstChild("chatter")
    repeat wait() until PG.chatter:FindFirstChild("textboxy")
    local Parent = player:WaitForChild("PlayerGui").chatter.textboxy
    for i,v in pairs(Parent:GetChildren()) do
        if v.Name:sub(1,4):lower() == "line" then
            local LineNumber = v.Name:sub(5)
            if LineNumber == "9" then
                v:Destroy()
            else
                v.Name = "line"..tostring(tonumber(LineNumber) + 1)
                v.Position = v.Position - UDim2.new(0,0,0,20)
            end
        end
    end
    newchatline = Instance.new("TextLabel",player:WaitForChild("PlayerGui").chatter.textboxy)
    if player then
        newchatline.Text = player.Name.. ": " ..message
    else
        newchatline.Text = "System Message: " ..message
    end     
    newchatline.Size = UDim2.new(1,0,0,20)
    newchatline.Position = UDim2.new(0,0,1,-20)
    newchatline.Font = "SourceSansBold"
    newchatline.TextColor3 = player:FindFirstChild("color").Value.Color
    newchatline.TextStrokeTransparency = 0
    newchatline.BackgroundTransparency = 1
    newchatline.BorderSizePixel = 0
    newchatline.FontSize = "Size18"
    newchatline.TextXAlignment = "Left"
    newchatline.TextYAlignment = "Top"
    newchatline.ClipsDescendants = true
    newchatline.Name = "line1"
    game:GetService("ReplicatedStorage").Chatted:InvokeServer(message)
end)

Server script: Message clones onto everyone's screens other than sender as intended, although it DOES NOT move the local message up one, for example if I send 3 messages "msg1""msg2""msg3" and then someone else sent one ("msg4") it would just overlap with message 3 and not send it up one rung of the ladder, if another person was to send a message after that it would move msg4 up but the local mesages would remain in place, I don't really understand this! From what I gather it is because the server script cannot access the local gui because of filtering enabled and therefore cannot move it up as it does not exist! The only way I can think of getting around this is by make everything client side, but I really wanted to do it this way in order to reduce lag!

Any ideas?

    local PG  = player:WaitForChild("PlayerGui")
    repeat wait() until PG:FindFirstChild("chatter")
    repeat wait() until PG.chatter:FindFirstChild("textboxy")
    for i,v in pairs(game:GetService("Players"):GetPlayers()) do
        local Parent = v:WaitForChild("PlayerGui").chatter.textboxy
        for i,v in pairs(Parent:GetChildren()) do
            if v.Name:sub(1,4):lower() == "line" then
                local LineNumber = v.Name:sub(5)
                if LineNumber == "9" then
                    v:Destroy()
                else
                    v.Name = "line"..tostring(tonumber(LineNumber) + 1)
                    v.Position = v.Position - UDim2.new(0,0,0,20)
                end
            end
        end
        if v.Name ~= player.Name then
            newchatline = Instance.new("TextLabel",v:WaitForChild("PlayerGui").chatter.textboxy)
            if player then
                newchatline.Text = player.Name.. ": " .. message
            else
                newchatline.Text = "System Message: " .. message
            end     
            newchatline.Size = UDim2.new(1,0,0,20)
            newchatline.Position = UDim2.new(0,0,1,-20)
            newchatline.Font = "SourceSansBold"
            newchatline.TextColor3 = player:FindFirstChild("color").Value.Color
            newchatline.TextStrokeTransparency = 0
            newchatline.BackgroundTransparency = 1
            newchatline.BorderSizePixel = 0
            newchatline.FontSize = "Size18"
            newchatline.TextXAlignment = "Left"
            newchatline.TextYAlignment = "Top"
            newchatline.ClipsDescendants = true
            newchatline.Name = "line1"
        end 
    end
    local Parent2 = game:GetService("StarterGui").chatter.textboxy
    for i,v in pairs(Parent2:GetChildren()) do
        if v.Name:sub(1,4):lower() == "line" then
            local LineNumber = v.Name:sub(5)
            if LineNumber == "9" then
                v:Destroy()
            else
                v.Name = "line"..tostring(tonumber(LineNumber) + 1)
                v.Position = v.Position - UDim2.new(0,0,0,20)
            end
        end
    end
    if newchatline then
        newchatline:Clone().Parent = game:GetService("StarterGui").chatter.textboxy
    end

1 answer

Log in to vote
1
Answered by 10 years ago

You could make a queue in the client. When it receives a message from the server, add it to the back of the queue. Have a LocalScript work through the queue from the start of the queue, generating TextLabels for the messages. When the LocalScript moves to the next message in the queue, move all the TextLabels up that have already been created.

Ad

Answer this question