String into colorsequence

What i want to achieve is to convert string into a color sequence.

The string will be the tostring of a existing colorsequence.

local csstring=tostring(workspace.ParticleEmitter.Color)

Now how to convert it back to color sequence?

1 Like

first of all using tostring without your custom formatter is a terrible idea to beggin with.
Anyway here is an example:

local c = ColorSequence.new({ColorSequenceKeypoint.new(0,Color3.new(1,1,1)),ColorSequenceKeypoint.new(0.5,Color3.new(1,0,0)),ColorSequenceKeypoint.new(1,Color3.new(0,1,0))})

local str = tostring(c)
warn(str)
local parsed = table.create(#str)::{number}
for i,v in string.split(str," ") do
	parsed[i] = tonumber(v)
end

local sequence_tbl = table.create(#parsed/5)::{ColorSequenceKeypoint}
for i=1,#parsed,5 do
	local n,r,g,b = table.unpack(parsed,i,i+3)
	table.insert(sequence_tbl,ColorSequenceKeypoint.new(n,Color3.new(r,g,b)))
end


local result = ColorSequence.new(sequence_tbl)
print(result==c)-->true

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.