Door not opening using TweenService and Vector3

I’m trying to make a door for an in-game shop. So, I am programming the door to make it open using tween service. I am an intermediate scripter, so I need some help with the script for the door.

The problem is that the door doesn’t do anything when I touch it, I also wanted the door to detect a player and it will open.

Here is the script I made for the door:

local ld = script.Parent
local rd = workspace.rIGHTDOOR.Union
local playerclose = 10
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(1)

-- opening (issue snippet)
ld.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			local torso = character:FindFirstChild("Torso")
			if torso then
				local distance = (torso.Position - ld.Position).Magnitude
				if distance <= playerclose then
					local goal = {Position = Vector3.new(20.25, 5.5, 10.5)}
					local tween = tweenservice:Create(ld,tweeninfo,goal)
					tween:Play()
					wait(1)
					local goal2 = {Position = Vector3.new(20.25, 5.5, 2.5)}
					local tween2 = tweenservice:Create(rd,tweeninfo,goal2)
					tween2:Play()
					wait(1)
					local goal3 = {Position = Vector3.new(20.25, 5.5, 10.5)}
					local tween3 = tweenservice:Create(rd,tweeninfo,goal3)
					tween3:Play()
					wait(1)
					local goal4 = {Position = Vector3.new(20.25, 5.5, 2.5)}
					local tween4 = tweenservice:Create(ld,tweeninfo,goal4)
					tween4:Play()
				end
			end
		end
	end
end)

-- closing
ld.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			local torso = character:FindFirstChild("Torso")
			if torso then
				local distance = (torso.Position - ld.Position).Magnitude
				if distance >= playerclose then
					local goal = {Position = Vector3.new(20.25, 5.5, 2.5)}
					local tween = tweenservice:Create(ld,tweeninfo,goal)
					tween:Play()
				end
			end
		end
	end
end)

This is the video that shows the issue:

And these are the objects I used to make the door:

Screenshot 2024-04-11 193813

I appreciate any help, thanks!

1 Like

Have you tried adding any print statements to check where the issue could be?

2 Likes

r15 characters do not have Torso as a child by default, only upper/lower torso

1 Like

it doesn’t have an error like you say, it’s like some instance that make it wrong or not existent.

1 Like
local ld = script.Parent
local rd = workspace.rIGHTDOOR.Union
local playerclose = 10
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(1)

-- opening (issue snippet)
ld.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			local hrp = character:FindFirstChild("HumanoidRootPart")
			if hrp then
				local distance = (hrp.Position - ld.Position).Magnitude
				if distance <= playerclose then
					local goal = {Position = Vector3.new(20.25, 5.5, 10.5)}
					local tween = tweenservice:Create(ld,tweeninfo,goal)
					tween:Play()
					wait(1)
					local goal2 = {Position = Vector3.new(20.25, 5.5, 2.5)}
					local tween2 = tweenservice:Create(rd,tweeninfo,goal2)
					tween2:Play()
					wait(1)
					local goal3 = {Position = Vector3.new(20.25, 5.5, 10.5)}
					local tween3 = tweenservice:Create(rd,tweeninfo,goal3)
					tween3:Play()
					wait(1)
					local goal4 = {Position = Vector3.new(20.25, 5.5, 2.5)}
					local tween4 = tweenservice:Create(ld,tweeninfo,goal4)
					tween4:Play()
				end
			end
		end
	end
end)

Thanks, but should I modify something to make the player be detected by the door?

1 Like
local ld = script.Parent
local rd = workspace.rIGHTDOOR.Union
local playerclose = 10
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(1)

-- opening (issue snippet)
ld.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			local hrp = character:FindFirstChild("HumanoidRootPart")
			if hrp then
				local distance = (hrp.Position - ld.Position).Magnitude
				if distance <= playerclose then
					local goal = {Position = Vector3.new(20.25, 5.5, 10.5)}
					local tween = tweenservice:Create(ld,tweeninfo,goal)
					tween:Play()
					wait(1)
					local goal2 = {Position = Vector3.new(20.25, 5.5, 2.5)}
					local tween2 = tweenservice:Create(rd,tweeninfo,goal2)
					tween2:Play()
					wait(1)
					local goal3 = {Position = Vector3.new(20.25, 5.5, 10.5)}
					local tween3 = tweenservice:Create(rd,tweeninfo,goal3)
					tween3:Play()
					wait(1)
					local goal4 = {Position = Vector3.new(20.25, 5.5, 2.5)}
					local tween4 = tweenservice:Create(ld,tweeninfo,goal4)
					tween4:Play()
				end
			end
		end
	end
end)


ld.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			local hrp = character:FindFirstChild("HumanoidRootPart")
			if hrp then
				local distance = (hrp.Position - ld.Position).Magnitude
				if distance > playerclose then
					local goal = {Position = Vector3.new(20.25, 5.5, 2.5)}
					local tween = tweenservice:Create(ld,tweeninfo,goal)
					tween:Play()
				end
			end
		end
	end
end)

I added a snippet to make it close, but there is something wrong in the action, and I’m not very good using TweenService.

This is what happens when i touch the door