Tween Not Working Properly

So I want the door to tween up then tween down but the problem is that it just goes to the wrong position, Here is a video on the problem and my script.

robloxapp-20220810-1834499.wmv (1.4 MB)

(Sorry if you need to download it and
the video is low quality, I’m lazy to download OBS)

local TweenService = game:GetService("TweenService")
local Door = game.Workspace.Door.Door1Part
local DoorOpenPart = game.Workspace.Door.Door1PartDestinationOpen
local DoorClosePart = game.Workspace.Door.Door1PartDestinationClose
local debounce = false

ClickDetector.MouseClick:Connect(function(plr)
	if not debounce then
		debounce = true
		if plr.Backpack:FindFirstChild("Level1Keycard" or "Level2Keycard") then
			print("Valid Keycard!")
			for i,v in pairs(game.Workspace.Door.Lights:GetChildren()) do
				v.BrickColor = BrickColor.new("Lime green")
			end
			local DoorOpenTweenInfo = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
			local DoorOpenTween = TweenService:Create(Door,DoorOpenTweenInfo,{Position = Vector3.new(DoorOpenPart.Position)})
			DoorOpenTween:Play()
			wait(1.5)
			local DoorCloseTweenInfo = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
			local DoorCloseTween = TweenService:Create(Door,DoorCloseTweenInfo,{Position = Vector3.new(DoorClosePart.Position)})
			DoorCloseTween:Play()
			for i,v in pairs(game.Workspace.Door.Lights:GetChildren()) do
				v.BrickColor = BrickColor.new("Really black")
			end
			wait(1)
			debounce = false
		else
			print("Invalid Keycard!")
			for i,v in pairs(game.Workspace.Door.Lights:GetChildren()) do
				v.BrickColor = BrickColor.new("Really red")
			end
			wait(1.5)
			for i,v in pairs(game.Workspace.Door.Lights:GetChildren()) do
				v.BrickColor = BrickColor.new("Really black")
			end
			wait(1)
			debounce = false
		end
	end
end)

I think its .cframe not .position im not sure:

local DoorOpenTween = TweenService:Create(Door,DoorOpenTweenInfo,{Position = Vector3.new(DoorOpenPart.CFrame)})

+i cant open the video

It ended up in the same wrong position…

This script here should work.

local TweenService = game:GetService("TweenService")
local Door = game.Workspace.Door.Door1Part
local DoorOpenPart = game.Workspace.Door.Door1PartDestinationOpen
local DoorClosePart = game.Workspace.Door.Door1PartDestinationClose
local debounce = false

ClickDetector.MouseClick:Connect(function(plr)
	if not debounce then
		debounce = true
		if plr.Backpack:FindFirstChild("Level1Keycard") or plr.Backpack:FindFirstChild("Level2Keycard") then -- The previous statement would only check for the first string
			print("Valid Keycard!")
			for i,v in pairs(game.Workspace.Door.Lights:GetChildren()) do
				v.BrickColor = BrickColor.new("Lime green")
			end
			local DoorOpenTweenInfo = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
			local DoorOpenTween = TweenService:Create(Door,DoorOpenTweenInfo,{Position = DoorOpenPart.Position}) -- The position was already a Vector3, therefore it would default to (0, 0, 0)
			DoorOpenTween:Play()
			wait(1.5)
			local DoorCloseTweenInfo = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
			local DoorCloseTween = TweenService:Create(Door,DoorCloseTweenInfo,{Position = DoorClosePart.Position}) -- The position was already a Vector3, therefore it would default to (0, 0, 0)
			DoorCloseTween:Play()
			for i,v in pairs(game.Workspace.Door.Lights:GetChildren()) do
				v.BrickColor = BrickColor.new("Really black")
			end
			wait(1)
			debounce = false
		else
			print("Invalid Keycard!")
			for i,v in pairs(game.Workspace.Door.Lights:GetChildren()) do
				v.BrickColor = BrickColor.new("Really red")
			end
			wait(1.5)
			for i,v in pairs(game.Workspace.Door.Lights:GetChildren()) do
				v.BrickColor = BrickColor.new("Really black")
			end
			wait(1)
			debounce = false
		end
	end
end)

For more information: Vector3 | Roblox Creator Documentation

1 Like

Thank you for the solution, I may have get stuck on this problem for a long time.

You might also want to check if the player has the keycard equipped by checking if the keycard is in their character.

1 Like