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

How do I add Tips into my chat GUI?

Asked by 10 years ago

I am trying to add like something to were every like 30 seconds something pops up in the chat GUI. I would like it to were like [SERVER INFO]: Words....

Chat GUI:

function UpdateOldLabels(Parent)
    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 == "12" then
                v:Destroy()
            else
                v.Name = "line"..tostring(tonumber(LineNumber) + 1)
                v.Position = v.Position - UDim2.new(0,0,0,15)
            end
        end
    end
end

game:GetService("Players").PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        for _,v in ipairs(game:GetService("Players"):GetChildren()) do
            UpdateOldLabels(v:WaitForChild("PlayerGui").ChatGui.Frame)
            newchatline = Instance.new("TextLabel",v:WaitForChild("PlayerGui").ChatGui.Frame)
            newchatline.Text = player.Name=='EmperorF' and ("[SMITE FOUNDER] "..player.Name.. ": " ..msg) or (player.Name.. ": " ..msg)
            newchatline.Size = UDim2.new(1,0,0,15)
            newchatline.Position = UDim2.new(0,0,1,-15)
            newchatline.Font = "SourceSansBold"
            newchatline.TextColor3 = player.Name=="EmperorF" and BrickColor.new("Bright red").Color or player.TeamColor.Color
            newchatline.TextStrokeTransparency = 0
            newchatline.BackgroundTransparency = 1
            newchatline.BorderSizePixel = 0
            newchatline.FontSize = "Size14"
            newchatline.TextXAlignment = "Left"
            newchatline.TextYAlignment = "Top"
            newchatline.ClipsDescendants = true
            newchatline.Name = "line1"
        end
        UpdateOldLabels(game:GetService("StarterGui").ChatGui.Frame)
        newchatline:Clone().Parent = game:GetService("StarterGui").ChatGui.Frame
    end)
end)

1 answer

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

The best way to do it would be to treat it like normal chat.

Unfortunately, the code you have does not modularly render a line of a chat, so we have to rework it a little.

Since when we're chatting we specify the player and what they said, we need to make our chat function take those in and work. We use the same procedure, however, for this.

function Chat(msg,player)
        for _,v in ipairs(game:GetService("Players"):GetChildren()) do
            UpdateOldLabels(v:WaitForChild("PlayerGui").ChatGui.Frame)
            newchatline =
                Instance.new("TextLabel",
                v:WaitForChild("PlayerGui").ChatGui.Frame)
            newchatline.Text =
                player.Name=='EmperorF'
                and ("[SMITE FOUNDER] "..player.Name.. ": " ..msg)
                or (player.Name.. ": " ..msg)
            newchatline.Size = UDim2.new(1,0,0,15)
            newchatline.Position = UDim2.new(0,0,1,-15)
            newchatline.Font = "SourceSansBold"
            newchatline.TextColor3 =
                player.Name=="EmperorF" and BrickColor.new("Bright red").Color
                or player.TeamColor.Color
            newchatline.TextStrokeTransparency = 0
            newchatline.BackgroundTransparency = 1
            newchatline.BorderSizePixel = 0
            newchatline.FontSize = "Size14"
            newchatline.TextXAlignment = "Left"
            newchatline.TextYAlignment = "Top"
            newchatline.ClipsDescendants = true
            newchatline.Name = "line1"
        end
        UpdateOldLabels(game:GetService("StarterGui").ChatGui.Frame)
        newchatline:Clone().Parent =
            game:GetService("StarterGui").ChatGui.Frame
end

We then just use that function inside the Chatted event.

game:GetService("Players").PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        Chat(msg,player);
    end)
end)

Like this, the script will function exactly the same. The only new thing is the thing which automatically calls Chat, which would be something like this:

local Server = {Name="[INFO]", TeamColor=BrickColor.new("Bright blue")};
-- Since we ask for the Name and BrickColor on players, we need
-- to make an object which has those properties.
while true do
    wait(30);
    Chat("I like apples.",Server);
    wait(30);
    Chat("Don't forget your coats you hung up in the waiting room!",Server);
end
Ad

Answer this question