I searched through the dev forum and found these topics:
I made the current code with the help of them but noticed that the minus can be placed anywhere on the textbox, even a the end.
If you use any number-only textbox at roblox studio (from the properties tab or any other) you’ll get what I mean, the minus sign can only be placed at the 1st character position.
Any help is appreciated.
Edit: found this page on Lua strings patterns and character classes but I can’t find out how to use them for what I want to achieve, but leaving it here might be useful for someone I guess.
textBox:GetPropertyChangedSignal("Text"):Connect(function()
if textBox.Text ~= nil then
textBox.Text = string.match(textBox.Text, "%-?%d+%.?%d*")
end
end)
but throws this:
Unable to assign property Text. string expected, got nil
in the output when I delete a character with backspace (the original you sent also throws it)
(replaced the v’s with textBox so anyone having the same issue as me can visualise it better)
The only “issue” is that when you type a minus at the left of a number that’s not the 1st character your selection moves 1 character to the right, (not an issue for me). If anyone knows how to fix this, answer to this topic, but that’s the solution I found.
Thank you to everybody who answered to this topic!