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

How to detect when a TextLabel "exits" the frame?

Asked by 3 years ago

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.

0
Why not set the frame's ClipDescendants property to true? It will hide any parts of the text label which are out of bounds. radiant_Light203 1166 — 3y
0
ok, but how do i detect it when it does that so i can destroy it? FirewolfYT_751 223 — 3y
0
because i think it would lag if there are 3000 chat messages FirewolfYT_751 223 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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)


0
no, because ChildRemoved is when something has been deleted, ClipDescendants only gets rid of the visibility of the object FirewolfYT_751 223 — 3y
Ad

Answer this question