I am making a chat GUI, but the scrollbar does not move enough. What it's designed to do is make the scrollingframe larger and scroll to the bottom when a new chat above line 22 (size) is present. It makes the scrollbar, but does not scroll down. Here's the code.
GUIData = {
ChatBoxSize = UDim2.new(1, 0, 0, 20),
ChatBoxStartPos = UDim2.new(0, 0, 1, -20),
FontSize = "Size18",
Color = Color3.new(1, 1, 1),
StrokeColor = Color3.new(1, 1, 1),
StrokeTrans = 1,
}
DesiredStyle = 2 --[[--Does 0 through 3, 4 styles--]]--
function HandleMessage(n, t, style)
local text = nil
if style == 0 then
local text = n .. " : " .. t
return text
elseif style == 1 then
local text = "["..n.."]: " .. t
return text
elseif style == 2 then
local text = "<"..n..">: " .. t
return text
elseif style == 3 then
local text = "("..n.."): " .. t
return text
end
end
CS = 0
function UpdateOldLabels(Parent, playerG)
for i,v in pairs(Parent:GetChildren()) do
if v.Name:sub(1,4):lower() == "line" then
local LineNumber = v.Name:sub(5)
local T = v.Name
local LineNumberInt = tonumber(LineNumber)
if LineNumberInt >= 22 then
playerG.PlayerGui.ChatGUI.GUI.CanvasSize = playerG.PlayerGui.ChatGUI.GUI.CanvasSize + UDim2.new(0, 0, 0, A) --Add to the canvas size
v.Name = "line"..tostring(tonumber(LineNumber) + 1)
v.Position = v.Position - UDim2.new(0, 0, 0, A)
if playerG.PlayerGui.ChatGUI.GUI.CanvasPosition.Y == CS then
local A = 20
CS = CS + A/2
playerG.PlayerGui.ChatGUI.GUI.CanvasPosition = playerG.PlayerGui.ChatGUI.GUI.CanvasPosition + Vector2.new(0, CS) --Auto-scroll
elseif playerG.PlayerGui.ChatGUI.GUI.CanvasPosition.Y < CS then --Catch if the player scrolled up to view previous chats. Prevent auto-scroll if they are
playerG.PlayerGui.ChatGUI.GUI.CanvasPosition = playerG.PlayerGui.ChatGUI.GUI.CanvasPosition + Vector2.new(0, 0)
end
else
v.Name = "line"..tostring(tonumber(LineNumber) + 1)
v.Position = v.Position - UDim2.new(0, 0, 0, 20)
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").ChatGUI.GUI, player)
newchatline = Instance.new("TextLabel",v:WaitForChild("PlayerGui").ChatGUI.GUI)
newchatline.Text = HandleMessage(player.Name, msg, DesiredStyle)
newchatline.Size = GUIData.ChatBoxSize
newchatline.Position = GUIData.ChatBoxStartPos
newchatline.Font = "SourceSans"
newchatline.TextColor3 = GUIData.Color
newchatline.TextStrokeTransparency = GUIData.StrokeTrans
newchatline.BackgroundTransparency = 1
newchatline.BorderSizePixel = 0
newchatline.FontSize = GUIData.FontSize
newchatline.TextXAlignment = "Left"
newchatline.TextYAlignment = "Center"
newchatline.ClipsDescendants = true
newchatline.TextWrapped = true
newchatline.Name = "line1"
end
UpdateOldLabels(game:GetService("StarterGui").ChatGUI.GUI, player)
newchatline:Clone().Parent = game:GetService("StarterGui").ChatGUI.GUI
end)
end)

2 comments
Are you using a ScrollBarFrame Gui, or scripted?
It's an instance called ScrollingFrame which has a UDim2 of the canvas size (the scrolling area) and Vector2 CanvasPosition which is where the scroll bar is. This script is in ServerScriptStorage, it's scripted.