#Why is This Tween Lagging

1 messages · Page 1 of 1 (latest)

neat bolt
#
local function animateToiletPaper(toiletPaperId)
    local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0)
    local toiletPapers = game.Workspace.ToiletPaper:GetChildren()
    local goldToiletPaper = game.Workspace.GoldToiletPaper:GetChildren()
    
    local toiletPaper = nil
    
    for _, v in toiletPapers do
        if v.Name == toiletPaperId then toiletPaper = v end
    end
    
    for _, v in goldToiletPaper do
        if v.Name == toiletPaperId then toiletPaper = v end
    end
    
    if toiletPaper == nil then return end

    local up = TweenService:Create(toiletPaper, tweenInfo, {CFrame = CFrame.new(toiletPaper.Position.X, toiletPaper.Position.Y + 1, toiletPaper.Position.Z)})
    local down = TweenService:Create(toiletPaper, tweenInfo, {CFrame = CFrame.new(toiletPaper.Position.X, toiletPaper.Position.Y - 1, toiletPaper.Position.Z)})

    up:Play()
    
    up.Completed:Connect(function()
        if toiletPaper == nil then
            up:Destroy()
            down:Destroy()
        return end
        down:Play()
    end)
    
    down.Completed:Connect(function()
        if toiletPaper == nil then
            up:Destroy()
            down:Destroy()
            return end
        up:Play()
    end)    
end

This tween is slowly lagging my game over time. It starts out fine, but after 20 minutes or so it becomes extremely laggy

modern sphinx
#

Memory leak

zinc yarrow
#

is it creating new instances/objects and not destroying them?

bronze topaz
#

Do tweens on client only

#

Never on server

zinc yarrow
bronze topaz
#

Because if u do it on the server, it is responsible for updating EVERY client on the new values. (Tweens can be like loops, but on a small decimal value, updated by something crazy like 0.001 every milsecond to get the smooth animation)

zinc yarrow
#

damnit

#

now i gotta completely rework more systemscrying

bronze topaz
#

Yeah, it creates crazy strain on the server, especially if u have high player lobbies, and alot of tweens at the same time

zinc yarrow
#

shit dude im using them for bullet tracers