Currently, my custom text box shows like this:
However, there’s a lot of empty space at the end of the message, How would I get rid of this?
Here are both my scripts:
(Localscript in my GUI)
UserInputService = game:GetService('UserInputService')
event = game.ReplicatedStorage:WaitForChild('PlayerChatted')
function strip(s)
return (s:gsub('^%s*(.-)%s*$', '%1'))
end
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Slash then
script.Parent.Parent.Message.MessageBox:CaptureFocus()
end
end
end
end)
script.Parent.Parent.Message.MessageBox.FocusLost:Connect(function(enter)
if enter then
local trimmed = strip(script.Parent.Parent.Message.MessageBox.Text)
if trimmed ~= '' then
event:FireServer(trimmed)
end
script.Parent.Parent.Message.MessageBox.Text = ''
end
end)
event.OnClientEvent:Connect(function(filtered)
local textlabel = Instance.new('TextLabel', script.Parent)
textlabel.BackgroundTransparency = .8
textlabel.BorderSizePixel = 0
textlabel.BackgroundColor3 = Color3.new(1, 1, 1)
textlabel.Position = UDim2.new(0, 0, 1, 0)
textlabel.Size = UDim2.new(1, 0, 0.1, 0)
textlabel.Font = Enum.Font.Cartoon
textlabel.TextColor3 = Color3.new(1, 1, 1)
textlabel.TextSize = 14
textlabel.TextXAlignment = Enum.TextXAlignment.Left
textlabel.RichText = true
textlabel.Text = filtered
for i, v in pairs(script.Parent:GetChildren()) do
if not (v == script) then
v:TweenPosition(
UDim2.new(0, 0, v.Position.Y.Scale - 0.1, 0),
Enum.EasingDirection.InOut,
Enum.EasingStyle.Linear,
0,
false
)
if v.Position.Y.Scale <= 0 then
v:Destroy()
end
end
end
end)
(Script in ServerScriptService)
event = game.ReplicatedStorage:WaitForChild('PlayerChatted')
event.OnServerEvent:Connect(function(player, message)
local filtered = ('%s: %s'):format(
player.Name, game.Chat:FilterStringForBroadcast(message, player)
)
event:FireAllClients(filtered)
local x = 2 + message:len()/15
local y = x/2
local billboard = game.ReplicatedStorage:WaitForChild('ChatBillboard'):Clone()
billboard.Bubble.Display.Text = game.Chat:FilterStringForBroadcast(message, player)
billboard.Adornee = player.Character.Head
billboard.Size = UDim2.new(x, 0, y, 0)
game.Debris:AddItem(billboard, 4)
for i, v in pairs(player.Character.Head:GetChildren()) do
if v.Name == 'ChatBillboard' and v.ClassName == 'BillboardGui' then
v.StudsOffsetWorldSpace = Vector3.new(0, v.StudsOffsetWorldSpace.Y + y, 0)
v.Size = UDim2.new(v.Size.X.Scale * 0.7, 0, v.Size.Y.Scale * 0.7, 0)
if v.Size.X.Scale <= 1 then
v:Destroy()
end
end
end
billboard.Parent = player.Character.Head
end)