Storing NumberSequence in StringValue

While trying to figure out how to store a ParticleEmitter’s transparency for a “Hide Players” script I found out NumberSequenceValues aren’t a thing, so here’s a function for decrypting a NumberSequence stored in a StringValue using tostring():

--the stringvalue param should be the path to the stringvalue
local function decryptNumSeq(stringvalue)
	local valuetable = {}
	local timetable = {}
	local index = 0
	for v in string.gmatch(stringvalue.Value, "%S+") do
		index = index + 1
		if index % 3 == 1 then
			table.insert(timetable, tonumber(v))
		elseif index % 3 == 2 then
			table.insert(valuetable, tonumber(v))
		end
	end
	local NumberSeqKeypoints = {}
	for i,v in timetable do
		table.insert(NumberSeqKeypoints, NumberSequenceKeypoint.new(timetable[i], valuetable[i]))
	end
	return NumberSeqKeypoints
end

--example usage
local Particle = game.Workspace.ParticleEmitter
local stringval = Instance.new("StringValue", script)
stringval.Value = tostring(Particle.Transparency)
local Sequence = NumberSequence.new(decryptNumSeq(stringval))

Hope this is helpful for someone and hopefully NumberSequenceValues become a thing soon so this won’t be necessary

FYI: there is already a built-in way to this via attributes.

Particle:SetAttribute("Transparency", Particle.Transparency)
print(Particle:GetAttribute("Transparency")) -- NumberSequence

RobloxStudioBeta_JyplNgUWuk

6 Likes