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

How would I remove a certain amount of characters from a string?

Hi there,

I'm trying to make a Color3 selection system, the idea is you put a value into each of 3 textboxes and the lights around you tween to the colour you inputted into the boxes, but if somebody put something that wasn't of 3 characters or contained anything but numbers, you'd get an error which is common sense, of course as I said in the previous question I could just filter it out and display an error message and not fire the remote, but I want it to be instantaneously removing characters if they're the 4th character+

So far my code is as follows;

local advancedmode = script.Parent
local inputR = advancedmode.inputR
local inputG = advancedmode.inputG
local inputB = advancedmode.inputB

while wait() do
if string.len(inputR.Text) >= 4 then
	local charstodel = string.len(inputR.Text) - 3
	print(charstodel)
-- // How do I delete the right amount of characters from the string value? \\ --
	end
end

So how would I delete the amount of characters that is specified in the local variable charstodel?

Also you can review my previous question here despite it not going into much detail because I had no idea what to do at the time, but thankfully now I do (at least a little bit)

2 comments

0

wait so you want to make sure each color3 value is a max of 3 digits?

0

and if any number is is 4 digits roundn to 255

1 answer

You can use string.sub() to get the first 3 letters of a string;

local str = “Hello World!
local modStr = string.sub(str,1,3)

print(str) -- output: Hello World!
print(modStr) -- output: Hel

You can use this to only get the first 3 letters from the textbox and use that as the RGB value.

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