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

Why does If TextFits statments crash my game?

Asked by 5 years ago
Edited 5 years ago

For some reason, every time I run studios, it crashed because I added a TextFits if Statment in. Any way I could fix this?

ChatBar.Changed:connect(function()
    local YSize = 0
    ChatBar.Size = UDim2.new(1, -6, 0, ChatSettings.ChatFontSize + 2)
    if ChatBar.TextFits == false then
        YSize = YSize + 1
    end
    ChatBar.Size = UDim2.new(1, -6, 0, (YSize * ChatSettings.ChatFontSize) + ChatSettings.ChatFontSize + 2)
end)
0
Are you sure this is the issue? Try removing that if statement and see if it still crashes, keep the YSize increment part theCJarmy7 1293 — 5y

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
5 years ago

You have a Changed event on the TextBox. Basically what that means, is anytime a property of the TextBox is changed, that event will fire, which includes Size. You've gotten yourself into an eternal loop since TextBounds will change once text is entered, and due to your code, once the Changed event fires, it'll change the Chatbar's size, which in turn fires the Changed event again, and forever on. To fix this issue, instead of using the Changed event, consider using the InputBegan event.

Ad

Answer this question