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

How would I check if my GUI finished tweening so I can run code if it does?

Asked by 6 years ago
    mouse.Button1Down:Connect(function()
                local HarvestTime = target.WheatConfig.HarvestTime.Value
                local animation = Instance.new("Animation")
                animation.AnimationId = "http://www.roblox.com/Asset?ID=2194604752"
                local animTrack = Character.Humanoid:LoadAnimation(animation)
                Character.Humanoid.WalkSpeed = 0
                animTrack:Play()
                Player.PlayerGui.HarvestUI.UI.Bar:TweenSize(UDim2.new (0, 290, 0 ,41), "Out", "Quad", HarvestTime, true)
                end

I would like to check when my GUI is finished tweening, and when it is a certain size, say 0, 290, 0, 41. It would run the code I have written down, while if it doesn't finish tweening and never reaches 0, 290, 0, 41 in size It won't run anything. I am quite unsure as to how to do this.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The last argument to TweenSize is an optional callback which will run code after a GuiObject has finished tweening.

local HarvestTime = target.WheatConfig.HarvestTime

local function stuff() -- whatever the function is 
    -- do your code here.
end 
mouse.Button1Down:Connect(function()
    local animation = Instance.new("Animation")
    animation.AnimationId = "http://www.roblox.com/Asset?ID=2194604752"
    local animTrack = Character.Humanoid:LoadAnimation(animation)
    Character.Humanoid.WalkSpeed = 0
    animTrack:Play()

    Player.PlayerGui.HarvestUI.UI.Bar:TweenSize(
        UDim2.new(0, 290, 0 ,41), 
        Enum.EasingStyle.Out,
        Enum.EasingDirection.Quad
        HarvestTime.Value, 
        true,
        stuff -- the function      
    )

end)

0
You add in the time it takes until it finishes tweening in the tweening method. I see you use "HarvestTime". Just use wait(HarvestTime) and then run the code. LlamaKiddo 0 — 6y
0
Lel, incapaz know better AswormeDorijan111 531 — 6y
0
The callback will run if the tween finishes or is canceled which is why the state is passed as an argument. User#5423 17 — 6y
Ad

Answer this question