Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with a chat GUI, doesn't update text properly?

I'm currently developing a chat GUI for my game, it works, but it doesn't, if that makes sense.

Creates the storage (Works)

local storage = Instance.new("Folder",workspace)
storage.Name = "Chat"

local number = 1

repeat
	local value = Instance.new("StringValue",workspace.Chat)
	value.Name = "Line"..number
	number = number + 1
	wait()
until #game.Workspace.Chat:GetChildren() == 7

Change the GUI Text (Doesn't work)

game.Workspace.Chat.Line1.Changed:connect(function()
	script.Parent.Line1.Text = game.Workspace.Chat.Line1.Value
	script.Parent.Line2.Text = game.Workspace.Chat.Line2.Value
	script.Parent.Line3.Text = game.Workspace.Chat.Line3.Value
	script.Parent.Line4.Text = game.Workspace.Chat.Line4.Value
	script.Parent.Line5.Text = game.Workspace.Chat.Line5.Value
	script.Parent.Line6.Text = game.Workspace.Chat.Line6.Value
	script.Parent.Line7.Text = game.Workspace.Chat.Line7.Value
end)

Update the values (Doesn't work)

local player = game.Players.LocalPlayer

player.Chatted:connect(function(chatted)
	game.Workspace:FindFirstChild("Chat").Line2.Value = game.Workspace:FindFirstChild("Chat").Line1.Value
	game.Workspace:FindFirstChild("Chat").Line3.Value = game.Workspace:FindFirstChild("Chat").Line2.Value
	game.Workspace:FindFirstChild("Chat").Line4.Value = game.Workspace:FindFirstChild("Chat").Line3.Value
	game.Workspace:FindFirstChild("Chat").Line5.Value = game.Workspace:FindFirstChild("Chat").Line4.Value
	game.Workspace:FindFirstChild("Chat").Line6.Value = game.Workspace:FindFirstChild("Chat").Line5.Value
	game.Workspace:FindFirstChild("Chat").Line7.Value = game.Workspace:FindFirstChild("Chat").Line6.Value
	game.Workspace:FindFirstChild("Chat").Line1.Value = chatted
end)

For example, say if I say "Howdy", the gui will change to

Howdy
*Blank*
*Blank*
*Blank*
*Blank*
*Blank*
*Blank*

But if I then say "Helllo", it will change to

Helllo
Howdy
Howdy
Howdy
Howdy
Howdy
Howdy

How would I fix this?

2 answers

✓ Accepted answer

I believe for your UpdateValues script, your setting every chat line aside from line 1 to be the same thing.

Your code:

local player = game.Players.LocalPlayer

player.Chatted:connect(function(chatted)
    game.Workspace:FindFirstChild("Chat").Line2.Value = game.Workspace:FindFirstChild("Chat").Line1.Value 
    game.Workspace:FindFirstChild("Chat").Line3.Value = game.Workspace:FindFirstChild("Chat").Line2.Value
    game.Workspace:FindFirstChild("Chat").Line4.Value = game.Workspace:FindFirstChild("Chat").Line3.Value
    game.Workspace:FindFirstChild("Chat").Line5.Value = game.Workspace:FindFirstChild("Chat").Line4.Value
    game.Workspace:FindFirstChild("Chat").Line6.Value = game.Workspace:FindFirstChild("Chat").Line5.Value
    game.Workspace:FindFirstChild("Chat").Line7.Value = game.Workspace:FindFirstChild("Chat").Line6.Value --you have set every variable to become line 1, being howdy. 
    game.Workspace:FindFirstChild("Chat").Line1.Value = chatted --and this changes line 1 to be what you chatted, helllo.
end)

What you can do instead would be assign everything backwards, so every value changes to its respective chat, not just one. Like so:

local player = game.Players.LocalPlayer

player.Chatted:connect(function(chatted)
    game.Workspace:FindFirstChild("Chat").Line7.Value = game.Workspace:FindFirstChild("Chat").Line6.Value
    game.Workspace:FindFirstChild("Chat").Line6.Value = game.Workspace:FindFirstChild("Chat").Line5.Value
    game.Workspace:FindFirstChild("Chat").Line5.Value = game.Workspace:FindFirstChild("Chat").Line4.Value
    game.Workspace:FindFirstChild("Chat").Line4.Value = game.Workspace:FindFirstChild("Chat").Line3.Value
    game.Workspace:FindFirstChild("Chat").Line3.Value = game.Workspace:FindFirstChild("Chat").Line2.Value
    game.Workspace:FindFirstChild("Chat").Line2.Value = game.Workspace:FindFirstChild("Chat").Line1.Value
    game.Workspace:FindFirstChild("Chat").Line1.Value = chatted
end)

--Here, we can set one line to be the previous line, thus moving text down, instead of changing all the text to be the same thing.

As for your Changing Text script, it appears to be working fine. You say "Howdy", and line 1 becomes "Howdy".

If anything needs clarifying, please let me know and I'll do my best to make it clear. Hope this helps. :)

You are changing the text in the wrong order.

So basically - they all say Howdy because you change Line 2 into Line 3 - then afterwards Line 3 into Line 4.

What you need to do is change Line 9 into nothing, Line 8 into 9, and move DOWNWARDS rather than UPWARDS.

This discussion is preserved as it was. New answers, comments, and votes are closed.