In my custom chat UI, I have a frame for the area of the chat, and my system works in that it adds a text label featuring the player who typed it and the text (or if you want a better visualization, I'm working on a old Roblox recreation, and I'm using the 2006-2009 ish chat system).
What I want to do is detect if a text label has exited the bounds of the frame by any bit, and if so, destroy it. I'm doing this method because of, well, I'm not going to go into detail here, but basically screen sizes and stuff.
Here is my code if that helps.
script.Parent.FocusLost:Connect(function(enter) local enteredText = script.Parent.Text if enter then script.Parent.Text = "" game.ReplicatedStorage.Events.FilterChatMessages:FireServer(enteredText) end end) game.ReplicatedStorage.Events.SendFilteredMessage.OnClientEvent:Connect(function(username, filteredText) local text = Instance.new("TextLabel") text.RichText = true text.Font = Enum.Font.SourceSans text.TextSize = 14 text.BorderSizePixel = 0 text.BackgroundColor3 = Color3.fromRGB(180, 180, 180) text.TextColor3 = Color3.fromRGB(255, 255, 255) text.BackgroundTransparency = 0.5 text.Text = '<b><i><font color="rgb(255,165,0)">'..username..'; </font> '..filteredText..'</i></b>' text.Parent = script.Parent.Parent.ChatArea wait() text.Size = UDim2.new(0, text.TextBounds.X, 0, text.TextBounds.Y) end)
Let me know if you need any more information.
You could do this:
-- stuff local text = Instance.new("TextLabel") text.Name = "PlayerNameLabel" text.RichText = true text.Font = Enum.Font.SourceSans text.TextSize = 14 text.BorderSizePixel = 0 text.BackgroundColor3 = Color3.fromRGB(180, 180, 180) text.TextColor3 = Color3.fromRGB(255, 255, 255) text.BackgroundTransparency = 0.5 text.Text = '<b><i><font color="rgb(255,165,0)">'..username..'; </font> '..filteredText..'</i></b>' text.Parent = script.Parent.Parent.ChatArea wait() text.Size = UDim2.new(0, text.TextBounds.X, 0, text.TextBounds.Y) script.Parent.Parent.ChatArea.ChildRemoved:Connect(function(child) if child:IsA("TextLabel") then if child.Name == "PlayerNameLabel" then child:Destroy() end end end) end)