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
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
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