Multiply Particle Emitter Size

Say I have a particle emitter how would i go about multiplying its current size to be twice as large?
But in I have specifically sized particles I would like to scale to make larger in code.
The output when I attempt to multiply the size by 2 the output says
00:24:16.774 Workspace.Bewm.BOOM:13: attempt to perform arithmetic (mul) on NumberSequence and number - Server - BOOM:13

4 Likes

You can’t multiply a NumberSequence by a number. You can multiply a NumberRange by a number, but not a NumberSequence.

You can use the NumberSequence constructor to create a new NumberSequence with the same values as the old one, but multiplied by a number.

local newNumberSequence = NumberSequence.new(
	numberSequence:GetEnumerator():map(function(keyframe)
		return {
			Time = keyframe.Time,
			Value = keyframe.Value * 2,
		}
	end):toTable()
)

Here’s a quick example of how to use them:

local function map(enumerator: Enumerator<T>, callback: (T) -> U): Enumerator<U>
	return Enumerator.new(function()
		local nextKey, nextValue = enumerator:GetCurrent()
		if nextKey ~= nil then
			return nextKey, callback(nextValue)
		end
	end)
end

local function toTable(enumerator: Enumerator<T>): {T}
	local result = {}
	for _, value in enumerator:GetEnumerator() do
		table.insert(result, value)
	end
	return result
end
2 Likes

I’m getting.
I understand your code This is much simpler then the solution I was getting to. But this Enumerator thing isnt very clear to me.
01:17:17.890 ‘GetEnumerator’ is not a valid member of NumberSequence - Server - BOOM:72

Thank you but I’ve figured it out.
My function Simply you plug in the sequence and the scale :slight_smile: Hope this thread helps somebody someday.

local function multNumberSequence(sequence,Scale)
	local numberKeypoints2 = {}
	for i = 1, #sequence.Keypoints do
		local currKeypoint = sequence.Keypoints[i]
		table.insert(numberKeypoints2, NumberSequenceKeypoint.new(currKeypoint.Time,currKeypoint.Value*Scale))	
	end
		return NumberSequence.new(numberKeypoints2)
end

Seq=script.Parent.Attachment.ParticleEmitter.Size
script.Parent.Attachment.ParticleEmitter.Size=multNumberSequence(Seq, 2)

This is the source I pulled original concept code from NumberSequence | Roblox Creator Documentation

8 Likes

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