Tween not playing upon pressing button!

Hello developers!

I was scripting an elevator door and then suddenly I come up with an issue.
So, every time the player presses a button the door close tween will play. However, it didn’t!
I tried using print() and it prints upon pressing the button but the tween doesn’t play!

Script
local TweenService = game:GetService("TweenService")
local TweenSettings = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
local CloseDoorTween1 = TweenService:Create(script.Parent.Parent.Parent.Parent.Parent.Parent.Door1, TweenSettings, {CFrame = CFrame.new(script.Parent.Parent.Parent.Parent.Parent.Parent.Door1.Position + Vector3.new(1.5,0,1.5))})

script.Parent.ClickDetector.MouseClick:Connect(function(playerWhoClicked)
	print("Button clicked!")
	CloseDoorTween1:Play()
end)

Thanks! Waiting for a reply.

5 Likes

The tween settings are for 2D user interface only, you can’t add modifiers on 3D objects.

local TweenService = game:GetService("TweenService")
local TweenTime = TweenInfo.new(1)

local Door = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("Door1" ,5)
local Click = script.Parent:WaitForChild("ClickDetector" ,5)

if Door ~= nil and Click ~= nil then
	Click.MouseClick:Connect(function(Player)
		local Goal = {}
		Goal.Position = Vector3.new(Door.Position.X + 1.5, Door.Position.Y, Door.Position.Z + 1.5)		
		local Tween = TweenService:Create(Door, TweenTime, Goal)

		Tween:Play()
	end)
end
3 Likes

It seems to make it work but it’s going in the wrong direction. It’s going forward and right instead of closing (going left)

1 Like

Change the direction to whatever you want here

Goal.Position = Vector3.new(Door.Position.X + 1.5, Door.Position.Y, Door.Position.Z + 1.5)
4 Likes

Thank you so much! You’re my hero!

Have a nice day!

2 Likes