In my game there is a textbox you put roman numerals into. Certain roman numeral symbols can’t be repeated more than a certain number of times in a row, so this script is meant to set a limit. It succeeds in setting a limit to how many times a symbol can repeat throughout the whole string, but I need it to be for consecutive symbols only. For example, “MMMCMXCIX” should be allowed (more than 3 m’s but no more than 3 m’s in a row) but “MMMM” shouldn’t be allowed (more than 3 m’s in a row). The script below wouldn’t accept that first string even though it’s a valid roman numeral because there is more than 3 m’s. What do I do to make the limit be for symbols in succession only?
IS = 0
VS = 0
XS = 0
LS = 0
CS = 0
DS = 0
MS = 0
Input:GetPropertyChangedSignal("Text"):Connect(function()
symbols = {} -- Resets the list of symbols so they don't stack every time the text changes
IS = 0 -- Resets the count for each character so they don't stack every time the text changes
VS = 0
XS = 0
LS = 0
CS = 0
DS = 0
MS = 0
for v in Input.Text:gmatch(".") do -- Put every character of the string into a list
table.insert(symbols, v)
end
for i,v in pairs(symbols) do -- Counts how many times each symbol appears in the list
if string.upper(v) == "I" then
IS = IS + 1
end
if string.upper(v) == "V" then
VS = VS + 1
end
if string.upper(v) == "X" then
XS = XS + 1
end
if string.upper(v) == "L" then
LS = LS + 1
end
if string.upper(v) == "C" then
CS = CS + 1
end
if string.upper(v) == "D" then
DS = DS + 1
end
if string.upper(v) == "M" then
MS = MS + 1
end
end
if IS > 3 then
local substring = Input.Text:sub(1, #Input.Text - 1) -- Removes last character if limit is exceeded
Input.Text = substring
end
if VS > 1 then
local substring = Input.Text:sub(1, #Input.Text - 1)
Input.Text = substring
end
if XS > 3 then
local substring = Input.Text:sub(1, #Input.Text - 1)
Input.Text = substring
end
if LS > 1 then
local substring = Input.Text:sub(1, #Input.Text - 1)
Input.Text = substring
end
if CS > 3 then
local substring = Input.Text:sub(1, #Input.Text - 1)
Input.Text = substring
end
if DS > 1 then
local substring = Input.Text:sub(1, #Input.Text - 1)
Input.Text = substring
end
if MS > 3 then
local substring = Input.Text:sub(1, #Input.Text - 1)
Input.Text = substring
end
end)