Checking if TweenSize has ended in ModuleScript

I am trying to make animated gui of store to pop up when player clicks store button

the problem that I came across is the debounce of tweening
beacuse I tween in module script with TweenSize I don’t really know how to force local script to wait untill the tween has ended to make v = true/false

Local Script

local screenGui = script.Parent.Parent.Parent.Parent
local button = script.Parent
local frame = script.Parent.Parent.Parent:WaitForChild("Store")
local module = require(screenGui:WaitForChild("Scripts"):WaitForChild("GuiTweener"))

local StartSize = UDim2.new(.1,0,.2,0)
local EndSize = UDim2.new(.3,0,.8,0)

frame.Size = StartSize

local v = false

button.MouseButton1Up:Connect(function()
	if v == false then
		module.Tween(frame,EndSize,v)
		v = true
	else
		module.Tween(frame,StartSize,v)
		v = false
	end
end)

Module Script:

local TweenModule = {}

TweenModule.Tween = function(obj,EndSize,v)
	if v == false then
		obj.Visible = true
		obj:TweenSize(EndSize,Enum.EasingDirection.Out,Enum.EasingStyle.Back,.2,false)
	else
		obj:TweenSize(EndSize,Enum.EasingDirection.In,Enum.EasingStyle.Back,.2,false,function() obj.Visible = false end)

	end
end

return TweenModule

Module functions on call run a new thread, similar to task.spawn() as I recall. You can play the tween in the module and return the object to the local script so you are able to use the :Wait() method

Alternatively, you can make the function return the tween instance so you can play it on the local script and use .Completed:Wait()

1 Like