Tween being painfully slow

the tween is NOT lagging at all, i’ve looked at the properties of one of the objects i’m tweening and it’s changing

the tween is just taking a really long time to complete
script: regular script in serverscriptservice

local Lighting = game:GetService("Lighting")
local kitchenFolder = game.Workspace.AcademyFood
local setTable = kitchenFolder:WaitForChild("SetTable")
local breakfast = kitchenFolder:WaitForChild("Breakfast")
local dinner = kitchenFolder:WaitForChild("Dinner")
local tea = kitchenFolder:WaitForChild("Tea")
local tweenservice = game:GetService("TweenService")
local setTableInfo1 = TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local tableSetGoal1 = {Transparency = 0}

Lighting.Changed:Connect(function()
	if Lighting.ClockTime >= 8.5 and Lighting.ClockTime <= 10.5 then
		for i,v in pairs(setTable:GetChildren()) do
			local tween1 = tweenservice:Create(v, setTableInfo1, tableSetGoal1)
			tween1:Play()
			for i,b in pairs(breakfast:GetDescendants()) do
				local tween2 = tweenservice:Create(b, setTableInfo1, tableSetGoal1)
				tween2:Play()
				if Lighting.ClockTime == 10 then
					v.Transparency = 1
					b.Transparency = 1
				end		
			end
		end	

here’s a video of what i mean

i think it might be to do with the loop i use, but it could also be the easing style i use
i honestly dont know which easing style to use if it is that causing the issue

This part seems off. Only update if the clock is exactly at 10. idk

that’s just so when it turns 10AM, the breakfast and plates etc disappear
breakfast starts at 8:30AM in-game and finishes at 10AM in-game

Did you try changing on what intervals the Tween uses?
You should also try linear, out. Maybe that’ll fix it?

What do you mean by intervals? If you mean the .5 in TweenInfo, yes I did. I tried 2, 1 and .5
I’ll try linear and out now.

have you tried it without Enum.EasingDirection.In?

Not sure how you are adjusting the clocktime, but I’m assuming its for a day/night cycle and clocktime is changed very frequently.

If that is the case, then changed event is being fired very rapidly, so when it finally reaches the 8.5 mark, the tween isn’t fired one once, but multiple times in a rapid succession, and since each tween overwrites the previous, the tween will constantly be playing since it takes 0.5 seconds to complete and thus will never finish (which is why it looks so laggy).

You can most likely fix this issue by adding a debounce so it fires only once and will stop more tweens from playing until the tweens are finished.

ocal Lighting = game:GetService("Lighting")
local kitchenFolder = game.Workspace.AcademyFood
local setTable = kitchenFolder:WaitForChild("SetTable")
local breakfast = kitchenFolder:WaitForChild("Breakfast")
local dinner = kitchenFolder:WaitForChild("Dinner")
local tea = kitchenFolder:WaitForChild("Tea")
local tweenservice = game:GetService("TweenService")
local setTableInfo1 = TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local tableSetGoal1 = {Transparency = 0}
local debounce = false

Lighting.Changed:Connect(function()
	if Lighting.ClockTime >= 8.5 and Lighting.ClockTime <= 10.5 and not debounce then
        debounce = true
		for i,v in pairs(setTable:GetChildren()) do
			local tween1 = tweenservice:Create(v, setTableInfo1, tableSetGoal1)
			tween1:Play()
			for i,b in pairs(breakfast:GetDescendants()) do
				local tween2 = tweenservice:Create(b, setTableInfo1, tableSetGoal1)
				tween2:Play()
				if Lighting.ClockTime == 10 then
					v.Transparency = 1
					b.Transparency = 1
				end		
			end
        task.wait(0.5)
        debounce = false
		end	

Hope this helps!

The tween wouldn’t run if i removed this

why would it not run if you removed it?

Linear and out fixed the problem.

Thank you!

No problem! Glad I could help.