Tween working every time except for the first time

I have this lever system in my game, and I tween it to turn on and off. The first time, the tweening is a bit off, but the rest of the times, it’s fine.

Here’s what it looks like in the explorer:
Screenshot 2023-03-29 104728

(The Values folder has Vector3Values that include the orientation and position of the stick when it’s off, and the orientation and position of the stick when it’s on.)

Here’s a video:

Here’s the script, ClickLeve:

local tweenServ = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Quint,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local model = script.Parent.Parent.Parent
local values = model.Values
local cooldown = false

script.Parent.MouseClick:Connect(function()
	if cooldown == false then
		cooldown = true
		if model.Stick.Position ~= values.OnPos.Value then
			tweenServ:Create(model.Stick,tweenInfo,{Position = values.OnPos.Value}):Play()
			tweenServ:Create(model.Stick,tweenInfo,{Orientation = values.OnOri.Value}):Play()
			-- Whatever I want to activate
		else
			tweenServ:Create(model.Stick,tweenInfo,{Position = values.OffPos.Value}):Play()
			tweenServ:Create(model.Stick,tweenInfo,{Orientation = values.OffOri.Value}):Play()
			-- Deactivation
		end
		task.wait(1.5)
		cooldown = false
	end
end)

Here is the other script, ValueHandler (I made this so I don’t have to input all the values every time I duplicate and move the lever):

local folder = script.Parent
local originPos = folder.Parent.Stick
local newPos = folder.Parent.OtherPos

folder.OffPos.Value = originPos.Position
folder.OnPos.Value = newPos.Position
folder.OffOri.Value = originPos.Orientation
folder.OnOri.Value = newPos.Orientation

If you need any of the values, just tell me and I will give them to you.

The problem may be because the switch’s initial position/orientation is different from the off position/orientation you have in your code. Making it look a bit whacky in animation. What I would do is make sure that the off position/orientation is identical to the initial position/orientation.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.