How do I continue Tween.Completed?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I created a Module Script containing a function that does tweening and I want to use tween.Completed for another script. For example when the tween is finished, I want to delete a BasePart when the transparency gets to 1.
  2. What is the issue? Include screenshots / videos if possible!
    I am unsure on how I can achieve this.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Well I could just copy the code from the module script and move it to where I need too, but It would also be great if there was a better solution.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Just incase here is the tween function

local module = {}

local tweenService = game:GetService("TweenService")
module.TweenFadeTransparency = function(ObjToTween)
	
	local timeToFade = 1
	local object = ObjToTween
	local tweenInfo = TweenInfo.new(timeToFade)
	local goal = {}

	if ObjToTween:IsA("TextLabel") then
		goal.BackgroundTransparency = 1
		goal.TextTransparency = 1
	elseif ObjToTween:IsA("Frame") then
		goal.BackgroundTransparency = 1
	elseif ObjToTween:IsA("BasePart") then
		goal.Transparency = 1
	end
	

	local tween = tweenService:Create(object, tweenInfo, goal)
	tween:Play()
	tween.Completed:Connect()
end

return module

and here is when I want to use the tween.Completed


function GameEnded()
	print("Intermission!")
	for i = IntermissionTime, 0, -1 do
		TimerEvent:FireAllClients(i)
		if i == IntermissionTime * 0.5 then
			print(i)
	 FadeEvent:FireAllClients(game.Workspace.CurrentMap:FindFirstChild(script.ChosenMap.Value))
			DeleteMap()
		end
		wait(1)
	end
end

I forgot that the module script function I made is being used on a Local Script, which should fire an event to the server so it can run the DeleteMap function. Its really confusing now that I think about it

local FadeEvent = game.ReplicatedStorage.RemoteEvents.FadeEvent

local TweenFunctions = require(game.ReplicatedStorage.TweenFunctions)

local tween = TweenFunctions.TweenFadeTransparency()

FadeEvent.OnClientEvent:Connect(function(TableToUse)
	print(TableToUse:GetChildren())
	for i, v in pairs(TableToUse:GetChildren()) do
		if v:IsA("Model") then
			for i,v2 in pairs(v:GetChildren()) do
				if v2:IsA("BasePart") then
					TweenFunctions.TweenFadeTransparency(v2)
					
				end
			end
		end
		if v:IsA("BasePart") then
			TweenFunctions.TweenFadeTransparency(v)
		end
	end
end)

So in summary, I made a tween inside a module script, I then want to use this tween inside a Local Script. Then with that I want to use the tween.Completed on a Server Script to delete parts.

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Is the function game ended in the module?

I am using a server script for the function

you could always do

repeat
wait()
until TweenInstance.PlaybackState == Enum.PlaybackState.Completed

why not have the game ended function in the module?

You could return the Tween after creating it in the function, then play it in whichever script is calling that module and connect it’s Completed event to the function that you want to fire.

1 Like

returning the tween in the module script worked! incase for the people who want to do this:

-- module script
local tween = tweenService:Create(object, tweenInfo, goal) -- tween service with variables
return tween
-- local script
local tween = TweenFunctions.TweenFadeTransparency() -- module script/tween
					tween:Play()
					tween.Completed:Connect(function()
						DeleteMapEvent:FireServer() -- This is a remote event to fire the Server which has the Delete function.
					end)