You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I am trying to create an effect where my particle emitters gradually get bigger to show the orb getting bigger.
What is the issue? Include screenshots / videos if possible!
The script works, however, it’s just not consistent and I’m not sure why. When I’m testing it, 80% of the time it does what it’s supposed to and I have no problems. Sometimes, however, the particles don’t tween all the way and there are no errors in the output either. I check the workspace and the size has not finished tweening and has halted. I am tweening a number value paired with a .changed event to tween the emitters. When they are interrupted, they end up looking like this.
Here is my code. (for one of the emitters as the code is the same for each of them just different sizes.) My code is in a local script so that the VFX is less laggy and smoother than if it were run in a server script. (though I’m pretty sure that the issue isn’t it having to be in a local script.)
local inner = particles.Inner
inner.Size = NumberSequence.new(0,0)
inner.Enabled = true
local innertwinfo = TweenInfo.new(0.8, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local innerobject1 = Instance.new("NumberValue")
innerobject1.Value = 0
local innergoal = {Value = 1}
local innertween = ts:Create(innerobject1, innertwinfo, innergoal)
innertween:Play()
innerobject1.Changed:Connect(function(newsize)
inner.Size = NumberSequence.new(newsize,0)
end)
innertween.Completed:Connect(function()
inner.Size = NumberSequence.new(1,0)
end)
*Note: seeing this bug I added a failsafe to where after the tween is completed, it should just manually change the size of the particle emitter to the one I want it to be without tweening it but this isn’t running either. (when the glitch happens.)
Any guidance is appreciated.
After looking into it a little more it seems that tweening a NumberSequence is just not a thing that should be occurring, it would benefit you much more to just use a loop as NumberSequence acts much like a tween on its own.
I’m not sure its the tween that’s the problem. I’m tweening a number value which should have no problems and using .Changed to update the number sequence. I want to figure out what’s stopping the script since even if the tween doesn’t finish, the tween.Completed doesn’t run either (even though the tween already started)
have it print every step of the tween that is being used to alter the number sequence and see if it is lagging behind at any certain point, maybe that will help you find your problem area.
The funny thing is I had that set up initially and then the bug just stopped happening so I just removed the prints assuming it was fixed. I’ll try to replicate it again though.
Okay so I added prints in the end manual size change, and a print on the .changed event. so my code looked like this.
local inner = particles.Inner
inner.Size = NumberSequence.new(0,0)
inner.Enabled = true
local innertwinfo = TweenInfo.new(0.8, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local innerobject1 = Instance.new("NumberValue")
innerobject1.Value = 0
local innergoal = {Value = 1}
local innertween = ts:Create(innerobject1, innertwinfo, innergoal)
innertween:Play()
innerobject1.Changed:Connect(function(newsize)
inner.Size = NumberSequence.new(newsize,0)
print(newsize)
end)
innertween.Completed:Connect(function()
inner.Size = NumberSequence.new(1,0)
print(5)
end)
When the bug happened, it printed newsize whenever the size changed but when the size stopped changing it stopped printing the newsize also. (it would print normally when the bug wouldn’t happen) And also at the end when it manually changes the size and it should print the number 5, that didn’t print also.
Here is the output:
It started printing the new sizes and then just stopped.
My guess is that it simply cannot keep up with the tween as the Changed function won’t fire anywhere near fast enough, your best bet is to just take the hit and use a loop. There may be another way I’m not seeing but I really don’t think firing a function as fast as the tween is running is a good idea, especially in terms of consistency and optimasation.