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

Lerp (Linear Interpolation) is not working. Can somebody help?

Asked by 7 years ago
TextBox.Focused:connect(function()
        for i = 0,1,0.01 do
        print(i)
        Frame.BackgroundColor3:lerp(colors[Color][800], i)
        Frame.Size:lerp(UDim2.new(XSize,0,0,3),i)
        wait(0.01)
        end
end)

you can probably predict what is going on here

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

Something you should know: lerping ScreenGuis is gratuitous

Use TweenSize!

TextBox.Focused:connect(function()
    local targetSize = UDim2.new(XSize,0,0,3);
    Frame:TweenSize(targetSize,"InOut","Linear",.2);
    repeat wait() until Frame.Size == targetSize;
end)
0
Sometimes this happens mightydifferent 85 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

When using lerp, I like to make functions so it's easier to do.

I made a simple function that goes through a table and lerps to whatever color is next;

function hb(num) --This function is just a Hearbeat:wait(); it makes the lerp smooth
    if num == 0 or num == nil then
        game:GetService("RunService").Heartbeat:wait()
    else
        for i = 0,num do
            game:GetService("RunService").Heartbeat:wait()
        end
    end
end

function llerp(gui,Table,timeToNextFrame,alpha,hbWait)
    spawn(function() --This is so you can run other code while the llerp function is being ran
        local Frame = 1 --Starting at table[1]
        for t = 1,#Table,1 do --Looping through the table
            print("TABLE: "..t) --This will print where the function is in the table
            if Frame > #Table then print'Done' break else Frame = Frame + 1 end --Checking if it is done going through the table, and if it isn't adds 1 to table
                for i = 0,1,alpha do --Alpha is the amount of times it will loop to get to 1. (.1 will be 10, .01 will be 100)
                    gui.BackgroundColor3 = gui.BackgroundColor3:lerp(Table[t],i) --Doing the lerp
                    hbWait = hbWait or 0 --If hbWait is nil, it will be 0
                    hb(hbWait) --Smooth waiting
                end
            wait(timeToNextFrame) --This is how long it will wait until lerping to the next color
        end
    end)
end

local colors = {
    Color3.new(1,0,0); --Red
    Color3.new(0,1,0); --Green
    Color3.new(0,0,1); --Blue
    Color3.new(1,1,1); --White
    Color3.new(0,0,0) --Black
}

--And finally, calling the function
llerp(script.Parent,colors,.5,.01,.01)
----Where the GUI is, the table for the colors, the time it takes to go to the next color, the amount of times it will loop to get to 1 (smaller numbers = smoother lerp), and the heartbeat:wait() (smaller numbers also = smoother lerp)

As for the Frame's size, simply use TweenSize;

Frame.Size:TweenSize(UDim2.new(XSize),0,0,3), "Out", "Sine")

Answer this question