Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Tweening not working properly, help?

Asked by 4 years ago
Edited 4 years ago

I am trying to tween the lighting's ColorShift_Top seamlessly while also making time go by. I made this script:

local Glows = {
    ["Morning_Glow"] = Color3.fromRGB(255, 140, 35),
    ["Noon_Glow"] = Color3.fromRGB(255, 255, 125),
    ["Evening_Glow"] = Color3.fromRGB(175, 45, 5),
    ["Night_Glow"] = Color3.fromRGB(15, 20, 75)
}

local function GetGlow()
    local CT = Lighting.ClockTime

    if CT > 6 and CT <= 8 then
        return Glows.Morning_Glow
    elseif CT > 8 and CT <= 16 then
        return Glows.Noon_Glow
    elseif CT > 16 and CT <= 18 then
        return Glows.Evening_Glow
    else
        return(Glows.Night_Glow)
    end
end

while true do
    Lighting.ClockTime = Lighting.ClockTime + increment

    local Ambient = Lighting.ColorShift_Top
    local NewAmbient = GetGlow()

    if Ambient == NewAmbient then
        Lighting.ColorShift_Top = NewAmbient
    else
        local newTween = TS:Create(Lighting, TI, {ColorShift_Top = NewAmbient})
        newTween:Play()
    end
    wait()
end

(Some parts not included.)

But when it tweens, it is vey slow. I know this is due to tweens overlapping, but how can I fix this? I need the tween to play in the "Background," with the rest of the script still running.

EDIT: The tweeninfo is:

TweenInfo.new(1.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In)

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Ok, here's how I fixed it. I first defined the colorTween as a filler tween in the start of the script:

local colorTween = TS:Create(Lighting, TI, {ColorShift_Top = Color3.fromRGB(0,0,0)})

This does nothing until the ambient changes, at which point it would check the playback state:

if Ambient == NewAmbient then
    Lighting.ColorShift_Top = NewAmbient
else
    if colorTween.PlaybackState ~= Enum.PlaybackState.Playing then
        colorTween = TS:Create(Lighting, TI, {ColorShift_Top = NewAmbient})
        colorTween:Play()
    end
end

This prevents it from running while it's already running.

0
You deserve an upvote mate. Block_manvn 395 — 4y
Ad

Answer this question