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

Why is my Custom Chat GUI not working?

Asked by 9 years ago

I'm making my own chat GUI but I wanted the name to be a different color to the message so I used a way I think would work. I've tried lots of things to fix it but when I chat nothing appears in the GUI, this is my script (It doesn't return an error so it must be something I've done):

CustomNames = {{"Player",Vector3.new(255/255,255/255,255/255)}}

game.Players.PlayerAdded:connect(function(plr)
    color = Vector3.new(math.random(0,255)/math.random(0,255),math.random(0,255)/math.random(0,255),math.random(0,255)/math.random(0,255))
    for i,v in pairs(CustomNames) do
        if plr.Name == v[1] then
            color = v[2]
            return
        end
    end
    plr.Chatted:connect(function(msg)
        for i,v in pairs(game.Players:GetChildren()) do
            gui = v:FindFirstChild("PlayerGui"):FindFirstChild("ChatGUI")
            for i,x in pairs(gui.Box:GetChildren()) do
                if x:IsA("TextLabel") then
                    x:TweenPosition(UDim2.new(x.Position-UDim2.new(0,0,0,-20)),"Out","Sine",0.5,true)
                    if x.AbsolutePosition.Y <= 0 then
                        x:remove()
                    end
                end
            end
            name = game.ReplicatedStorage.Text:Clone()
            name.Parent = gui.Box
            name.Position = UDim2.new(0,0,0,180)
            name.Size = UDim2.new(0,string.len(plr.Name)*10+10,0,20)
            name.Text = plr.Name..":"
            name.TextColor3 = color
            name.TextStrokeColor3 = color
            name.TextStrokeTransparency = 0.5
            chat = game.ReplicatedStorage.Text:Clone()
            chat.Parent = gui.Box
            chat.Position = UDim2.new(0,string.len(plr.Name)*10+10,0,180)
            chat.Size = UDim2.new(0,600-(string.len(plr.Name)*10+10),0,20)
            chat.Text = msg
            chat.TextColor3 = Vector3.new(255/255,255/255,255/255)
            chat.TextStrokeColor3 = Vector3.new(0/255,0/255,0/255)
            chat.TextStrokeTransparency = 0.8
        end
    end)
end)

1 answer

Log in to vote
-1
Answered by
nilVector 812 Moderation Voter
9 years ago

1) You can't use Vector3 for a color. Vector3's are for positioning (of parts). You have to use Color3.

2) When looping through a table, you must use ipairs. For example, when you tried to loop through your table, CustomNames, you have to do it like this:

for i, v in ipairs(CustomNames) do
    if plr.Name == v[1] then
        color = v[2]
        break
    end
end

3) Also, you may have noticed that I used breakabove instead of return. Unless I'm mistaken, you can only use returns when in functions. You're not using it in any function (except for the main one - .Chatted, which, in that case, it will exit out of the .Chatted function if it had even went through the for loop in the first place). breakwill take it out of the closest loop it is in. In your case, neither is necessary, but it's still okay to have it to reduce the ultimate run-time.

4) No where in code do I see your table of players and colors being updated as a player enters a game. Basically, in the for loop above, you're checking to see if plr's name is literally "Player". There's only one person out of the 80 million users in ROBLOX who's name is "Player" (unless you're testing in Studio, of course).

5) In your chat text GUI, you made the same mistake with Vector3's. You used Vector3 for a color when you should have used Color3.

Make these changes, and once you've fixed them, let me know. If they work, then great! If not, tell me any errors you received.

Ad

Answer this question