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

Why is my 'Chat Gui' code not working as supposed to?

Asked by 9 years ago

As the title explains, my Chat Gui is not working as supposed to, but instead, it's doing something else; It's getting the names mixed up, as it keeps changing their names to Chat1, Chat2, Chat4, Chat12, Chat7, ect., and not removing old Chats. Sadly, I can not provide any Output, as there is nothing showing up. Here is the code I am using:

repeat wait() until game.Players.LocalPlayer and script.Parent:FindFirstChild("Displayer")
local Displayer = script.Parent.Displayer;
local funcs = {};
local MaxChats = 8;

function onChat()
local num = 0; local num2 = 0; --This is used to help keep track of all the Chat's Names, and Gui positioning locations

for i = 1, #funcs do --This is used when a Player leaves, joins, or if the code just executed
funcs[i]:disconnect() --It will then proceed to disconnect the current functions it has in table 'funcs'
table.remove(funcs,i) --It will then remove it from the table 'funcs'
end

for i,plr in pairs(game.Players:GetPlayers()) do --This will loop through the Player's
local chatfunc = plr.Chatted:connect(function(msg) --This will connect the Player's Chat to the 'Gui'

for i2,v2 in pairs(script.Parent:GetChildren()) do --This is where the names are getting mixed up
if v2 ~= script and v2 ~= Displayer then --This will check if the Child is not the script itself, now the 'Displayer'
for x = 1, #v2.Name do --This is used to loop through the string of the Child's Name
if tonumber(v2.Name:sub(x,x)) then --This will check if the current character is a Number value
if tonumber(v2.Name:sub(x,x)) > MaxChats then --If so, it will check if the Number Value is over 'MaxChats', or '8', but sadly, it isn't
v2:Destroy() --It will destroy it
num = num - 1 --Minus 'num' by '1'
num2 = num2 - 1 --Minus 'num2' by '1'
end
end
end
local orig = v2.Name --This is used to save it's original name
v2.Name = orig:sub(1,4)..tonumber(orig:sub(5)) + 1 --This is used to change the Chat's Name; but sadly it just gets them all mixed up, and does not remove at that point
end
end

local Chat = Displayer:Clone() --This creates a new 'Gui' to displayer the Player's Chat
Chat.Parent = Displayer.Parent
Chat.Position = UDim2.new(0.2,0,0.04*num2,0)
Chat.Size = UDim2.new(0.4,0,0.04,0)
Chat.Name = "Chat"..num
Chat.Text = game.Players.LocalPlayer.Name..": "..msg
num = num + 1
num2 = num2 + 1
end)
table.insert(funcs,chatfunc)

end
end

game.Players.PlayerAdded:connect(onChat)
game.Players.PlayerRemoving:connect(onChat)
onChat() --

If I still did not correctly tad, just let me know.

1
Please tab your code correctly, it's hard to read. Perci1 4988 — 9y
0
Oh, sorry, I forgot about that. I shortened some of the lines to reduce code space, I'll tab them right now. TheeDeathCaster 2368 — 9y

1 answer

Log in to vote
-5
Answered by 9 years ago

try

for i2,v2 in pairs(script.Parent:GetChildren().Name) do

this will give you the names of the children rather than just the children

1
That will not work; 'GetChildren' creates a table of the current Children in the Parent 'Parent:GetChildren()', also, that would error because; I would be attempting to call '.Name' on a Table. TheeDeathCaster 2368 — 9y
0
what if script.Parent:GetChildren() was set to a variable then, that variable.Name would work fishing10 0 — 9y
1
No, it wouldn't, because 'local var = script.Parent:GetChildren() print(var.Name)' is still attempting to call '.Name' on a Table, or, if you mean individually, it wouldn't because there would be more than 2-5 chats each chat, thus, the variable would not work. TheeDeathCaster 2368 — 9y
0
oh ok fishing10 0 — 9y
Ad

Answer this question