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

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

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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. :)

Ad
Log in to vote
1
Answered by
3dsonicdx 163
7 years ago

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.

Answer this question