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

How would I check if this GUI tween has been completed?

Asked by 4 years ago
Edited 4 years ago

After doing some research, I have a feeling that it would be something with the .Completed event, but I can't figure out how I would implement that into my game. This is the code that is causing the problem.

I have a feeling it would be something to do with this line, I did try simply waiting 6 seconds and then removing it (Which is what I want to happen to the textLabel when the tween is complete) but adding the 6 second timer just messed with all other parts of my code.

textLabel:TweenPosition(UDim2.new(position, 0, -0.5, 0), nil, nil, 6)

I'll accept your answer if it works. :D

1 answer

Log in to vote
0
Answered by 4 years ago

Okay, I have my fixed answer here. The problem was that I needed to access "TweenService" in order to access the event of 'Completed', so I had to change around a few parts of my code. Below, I have my updated code that works, this will, when the GUI has finished tweening, will delete the TextLabel.

local TweenService = game:GetService("TweenService") -- had to use TweenService to access the event of 'Completed'
local WordLabel = script.Parent
local PositionLabel --Defined earlier on
local TweenInfoLabel = TweenInfo.new(3) -- '3' defines the amount of time that the tween takes place in

local NewTweenPosition = {} -- has to be a table
local NewTweenPosition = UDim2.new(PositionLabel, 0, -0.5, 0) --position I want the GUI to tween to

local tweenLabel = TweenService:Create(WordLabel, tweenInfoLabel, NewTweenPosition) -- creating the tween with all parameters

tweenLabel.Completed:Connect(function()
    WordLabel:Remove() -- removes the label when the tween has completed
end)
TweenLabel:Play() -- plays the tween

I have also added comments onto the sections that I was mainly confused on, which may lead to someone else in the future also being confused.

I hope this helps!

0
You can use the callback function of GuiObject:TweenPosition() to work in the same way as the Completed event of TweenService. This would probably work better for you: https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenPosition darkelementallord 686 — 4y
0
If you look in the actual question, I do use 'TweenPosition', however, like I say in my answer I gave, the TweenPosition' doesn't give a valid option of when the Tween has been completed. RyanTheLion911 195 — 4y
0
Either way, what I have wrote works. RyanTheLion911 195 — 4y
0
If you reread what darkelementallord said, you may see that the callback parameter of TweenPosition is the alternate of the Completed event. boredlake 256 — 1y
Ad

Answer this question