alright so i am completely new to scripting anything with strings and i got a system set up to when someone joins read a value and set the players color to that value but the issue is some of the value options wont be 11 characters long (124,92,70 something like that instead of 204, 142, 105) and when its like that it just sets the last 2 Color3 values to 0 because its trying to read the comma from it but i dont know how to filter the comma out and this is the best attempt ive had so far
Script:
local R = string.sub(Color.Value, 1, 3) if string.match(Color.Value,",",5,7) then local G = string.sub(Color.Value,5,6) else local G = string.sub(Color.Value, 5, 7) if string.match(Color.Value,",",8) then local B = string.sub(Color.Value,8) else local B = string.sub(Color.Value, 9) end end for i,v in pairs(char:GetChildren()) do if v:IsA("BodyColors") then v.HeadColor3 = Color3.fromRGB(R,G,B) v.LeftArmColor3 = Color3.fromRGB(R,G,B) v.LeftLegColor3 = Color3.fromRGB(R,G,B) v.RightArmColor3 = Color3.fromRGB(R,G,B) v.RightLegColor3 = Color3.fromRGB(R,G,B) v.TorsoColor3 = Color3.fromRGB(R,G,B) end end
like @voidofdeathfire has already pointed out, string.gsub() is the function you're looking for
the function has three parameters: a subject string, a pattern, and a replacement string.
here's an example on how it works:
local example = "1-2-3-4-5" local pattern = ',' -- what it will look for local replacement = ' ' -- and what it will replace with local result = string.gsub(example,pattern,replacement) print(result) -- expected result: 1 2 3 4 5
In your case, you want it to look like this
local given_string = tostring(Color.Value) -- this function will turn it into a string local pattern = ',' local replacement = ' ' string.gsub(given_string,pattern,replacement)