Tweening not working?

My script:

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local goalTop = Vector3.new(17, 8.6, 7)
local goalBottom = Vector3.new(17, -0.6, 7)
local returnTop = Vector3.new(17, 5.5, 7)
local returnBottom = Vector3.new(17, 2.5, 7)
local top = script.Parent.Top
local bottom = script.Parent.Bottom

function touched(Touched)
	connection:Disconnect()
	
	print(Touched.Name .. " touched")
	
	if not Touched.Parent:FindFirstChildWhichIsA("Humanoid") then connection = script.Parent.Touch.Touched:Connect(function(hit) touched(hit) end) return end
	print("Got past if")
	
	local tween1 = TweenService:Create(top, TweenInfo, {Position = goalTop})
	local tween2 = TweenService:Create(bottom, TweenInfo, {Position = goalBottom})
	local retTween1 = TweenService:Create(top, TweenInfo, {Position = returnTop})
	local retTween2 = TweenService:Create(bottom, TweenInfo, {Position = returnBottom})
	print("assigned")
	
	tween1:Play()
	tween2:Play()
	print("played?")
	tween1.Completed:Wait()
	wait(3)
	print("waited")
	retTween1:Play()
	retTween2:Play()
	retTween1.Completed:Wait()
	wait(2)
	
	connection = script.Parent.Touch.Touched:Connect(function(hit) touched(hit) end)
end

connection = script.Parent.Touch.Touched:Connect(function(hit) touched(hit) end)

It errors on line 18 giving me this:
image
Help me please!

1 Like

You define the tweenInfo as tweenInfo but you put TweenInfo inside the :Create()

1 Like

The TweenInfo variable you define on line 2 is called “tweenInfo,” but you’re passing “TweenInfo” to TweenService:Create. Like most languages, Lua variables are case-sensitive.

Your variable is tweenInfo, not TweenInfo. The reason why it is not saying it is undefined is because TweenInfo refers to the TweenInfo type which contains things like TweenInfo.new().

1 Like

Thank you so much, it works now! Also, this is a goodbye to this account on the DevForum. It just let me log in on @Mi_sst, so if you see them, you’re seeing me! Bye!

2 Likes

Just as a note in the future: please try to apply some basic to these kinds of problems before posting threads. Review your code, make sure you’re passing the right datatypes to functions and refer to the Developer Hub for API reference.

It is ill-advised and misuse of this category to dump your entire script into a thread, post an error and ask someone to solve it for you. Please make sure you try fixing this yourself, as per the category guidelines.

1 Like