Why is my tween service not working?

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 am trying to make my flag tween down when a player steps on it.

  1. What is the issue? Include screenshots / videos if possible!

I get no errors but the flag does not move at all. I checked the call script and the function is exactly the same name and I even put a print statement that prints out fine inside the function but it is not tweening.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried many discords but nobody is finding anything.

Module Code

local FlagService = {}

local Table = {
	__index = FlagService
}

local TweenService = game:GetService("TweenService")

local FlagPositions = {	
	Down = {Flag1 = Vector3.new(-54.348, 103.035, 298.019)};
	Up = {Flag1 = Vector3.new(-54.348, 120.375, 298.019)};
}

function FlagService.new(part)
	local newFlag = {}
	setmetatable(newFlag, Table)


	newFlag.FlagPart = part

	newFlag.DownTween = TweenService:Create(part, TweenInfo.new(10), {Position = FlagPositions.Down[part.Name]})
	newFlag.UpTween = TweenService:Create(part, TweenInfo.new(10), {Position = FlagPositions.Up[part.Name]})

	return newFlag
end

function FlagService:StartLower(waitUntilFinished)
	self.DownTween:Play()
end

function FlagService:StartRaise(waitUntilFinished)
	self.UpTween:Play()
end

function FlagService:PauseFlag()
	self.DownTween:Pause()
	self.UpTween:Pause()
end

function FlagService:ChangeIcon(player)
	local content, isReady = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

	repeat wait() until isReady 

	self.FlagPart.UI1.Frame.ImageLabel.Image = content
	self.FlagPart.UI2.Frame.ImageLabel.Image = content
end

function FlagService:ChangeFlagVisibility(state)
	self.FlagPart.UI1.Frame.ImageLabel.Visible = state
	self.FlagPart.UI2.Frame.ImageLabel.Visible = state
end

return FlagService
1 Like

Is the BasePart by any chance welded or attached in any way to something?

1 Like
local newFlag = {}
newFlag.__index = newFlag

See if that fixes things.

the base part is anchored and welded to other unanchored parts but that should not matter as it was anchored before and worked fine

it must have cut that part of the script off but I do have the FlagService = {} at the top

No like, the index should be set to itself not just an empty table. So you would do:

function FlagService.new(part)
	local newFlag = {}
	newFlag.__index = newFlag


	newFlag.FlagPart = part

	newFlag.DownTween = TweenService:Create(part, TweenInfo.new(10), {Position = FlagPositions.Down[part.Name]})
	newFlag.UpTween = TweenService:Create(part, TweenInfo.new(10), {Position = FlagPositions.Up[part.Name]})

	return newFlag
end

Have you tried to tween the CFrame instead?

well thats not the issue because like I said the functions prints fine and I used this OOP method before fine so its an iassue with the tween and not the OOP fucntionality

Are there any errors when you run it?

no not really, it just doesnt move and i dont know why

In the past, I’ve had issues with tweening the position property. Perhaps make all the values CFrame values and see if it works.

well i just tried it this way and it works fine

local flag = require(path.to.module).new(game:GetService("Workspace").Flag1)

flag:StartLower()

I dunno, it just moves.

but I dont think changing the way it is called would cause the tween
to just not work

just tried that and I still get the same result

Okay, check your entire Workspace (in the explorer search bar) for welds. Studio is quite sneaky in the sense that it likes to create automatic welds to other parts without you realising. Delete all welds (except for the ones you want) and try again. Additionally, the flag is better off welded together with WeldConstraints than regular Welds.
https://devforum.roblox.com/t/welds-not-working-with-tween/611989/4

Yah I just did that and it still doesnt work, however it does when create the tween directly inside the script instead of calling it from the module so I may need to not use a module

Then you are better off doing that if using a module is unnecessary. :wink:

1 Like
FlagPositions.Down[part.Name]

What is the position of the variable defined? I’m either assuming this references a Vector3 value or a part. If it is a Vector3, make sure that it is in the correct position, if it is a part then that’s the reason it doesn’t work.

A quick look at the hierarchy of the game would help a lot.

Can you send the code of you implementing the class.

it was just a wrong position variable so it was moving but to the position it was before. I should have noticed that lol. thanks for the help :grin: