Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

	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

✓ Accepted answer

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

3 comments

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.

0

Lel, incapaz know better

0

The callback will run if the tween finishes or is canceled which is why the state is passed as an argument.

This discussion is preserved as it was. New answers, comments, and votes are closed.