Hi, I made a few edits to the ROBLOX wiki custom chat gui and the one edit I made was when a certain player (In this case Player1) chatted he had rainbow text. That worked fine, but when he sent another text the first text wouldn't be rainbow anymore and the new text would be rainbow but the colors would change a lot faster. Can you please help?
script:
function rainbowtext() while true do wait(.1) newchatline.TextColor3 = Color3.new(0/255, 128/255, 1) wait(.1) newchatline.TextColor3 = Color3.new(33/255, 136/255, 157/255) wait(.1) newchatline.TextColor3 = Color3.new(78/255, 151/255, 59/255) wait(.1) newchatline.TextColor3 = Color3.new(175/255, 208/255, 37/255) wait(.1) newchatline.TextColor3 = Color3.new(253/255, 221/255, 0/255) wait(.1) newchatline.TextColor3 = Color3.new(231/255, 130/255, 48/255) wait(.1) newchatline.TextColor3 = Color3.new(197/255, 35/255, 20/255) wait(.1) newchatline.TextColor3 = Color3.new(97/255, 39/255, 123/255) end end function NewLabel(parent, msg, player) newchatline = Instance.new("TextLabel", parent) newchatline.Size = UDim2.new(1,0,0,30) newchatline.Position = UDim2.new(0,0,1,-30) newchatline.Font = "SourceSansBold" newchatline.TextStrokeTransparency = 0 newchatline.BackgroundTransparency = 1 newchatline.BorderSizePixel = 0 newchatline.FontSize = "Size18" newchatline.TextXAlignment = "Left" newchatline.TextYAlignment = "Top" newchatline.ClipsDescendants = true newchatline.Name = "line1" if player.Name == "Player1" then newchatline.Text = "[Owner]"..player.Name..": "..msg rainbowtext() else newchatline.TextColor3 = Color3.new(1,1,1) newchatline.Text = player.Name.. ": " ..msg end end 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 == "5" then v:Destroy() else v.Name = "line"..tostring(tonumber(LineNumber) + 1) v.Position = v.Position - UDim2.new(0,0,0,25) 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").ScreenGui.Frame) UpdateOldLabels(game:GetService("StarterGui").ScreenGui.Frame) NewLabel(v:WaitForChild("PlayerGui").ScreenGui.Frame, msg, player) NewLabel(game:GetService("StarterGui").ScreenGui.Frame, msg, player) end end) end)
Your loop changes the newchatline
variable.
At first, it works fine. You set the variable equal to the first line of text, and it changes color.
So now you want to add a second line of text. But now you change the newchatline
variable to equal this new line of text.
Since the loop only changes the color of newchatline
, it will not change the first line of text because newchatline
now equals the second line.
What you need is a loop to run for each individual chat line. You can make use of parameters and arguments for this.
function rainbowtext(gui) while wait(0.1) do --Just making it a random color is shorter and would probably be fine in your case gui.Color.TextColor3 = Color3.new(math.random(), math.random(), math.random()) end end
So now instead of relying on what a specific variable equals, this loop will continue to change what the parameter equals. Each time we call the function, we can make the parameter equal something different, causing separate loops to run for each line of text.
rainbowtext(newchatline)
Since newchatline
constantly changes to equal the newest line of text, this will cause a loop to run for each new line. But since we stored what it equals in a parameter, the loops will still run correctly once newchatline
changes.
Yo bro, You need to make sure that your loop ends! You didnt break the loop! Also the code could have been neater and very very simple so i took the pleasure of doing it for you! Change your first function and enter this instead. It works way better! Thumbs up and Like if helped!
function rainbowtext() wait(.1) newchatline.TextColor3 = Color3.new(math.random(0,255)/255, math.random(0,255)/255, math.random(0,255)/255) end
If you are trying to change the TextColor of your text just simply do this:
function rainbowtext() while wait() do newchatline.TextColor3 = BrickColor.Random().Color -- OR color3.new(math.random(), math.random(), math.random()) if you don't wanna be limited to roblox's colors (thx you Perci1) end end function NewLabel(parent, msg, player) newchatline = Instance.new("TextLabel", parent) newchatline.Size = UDim2.new(1,0,0,30) newchatline.Position = UDim2.new(0,0,1,-30) newchatline.Font = "SourceSansBold" newchatline.TextStrokeTransparency = 0 newchatline.BackgroundTransparency = 1 newchatline.BorderSizePixel = 0 newchatline.FontSize = "Size18" newchatline.TextXAlignment = "Left" newchatline.TextYAlignment = "Top" newchatline.ClipsDescendants = true newchatline.Name = "line1" if player.Name == "Player1" then newchatline.Text = "[Owner]"..player.Name..": "..msg rainbowtext() else newchatline.TextColor3 = Color3.new(1,1,1) newchatline.Text = player.Name.. ": " ..msg end end 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 == "5" then v:Destroy() else v.Name = "line"..tostring(tonumber(LineNumber) + 1) v.Position = v.Position - UDim2.new(0,0,0,25) 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").ScreenGui.Frame) UpdateOldLabels(game:GetService("StarterGui").ScreenGui.Frame) NewLabel(v:WaitForChild("PlayerGui").ScreenGui.Frame, msg, player) NewLabel(game:GetService("StarterGui").ScreenGui.Frame, msg, player) end end) end) --By DZ3 this has not been tested.