Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does If TextFits statments crash my game?

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)

1 comment

0

Are you sure this is the issue? Try removing that if statement and see if it still crashes, keep the YSize increment part

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.