Alright so, i'm trying to make a sliding door. But what it does is when i close it, it has a offset of about a stud. From where it needs to be, and ideas to fix this?

SCREEN SHOTS:

Problem

Open State

What i need to happen / Closed State

Door Setup

Code:

local keycard = script.Parent
local door1 = keycard.Parent:FindFirstChild("Door1")
local door2 = keycard.Parent:FindFirstChild("Door2")
local levels = {
	["Admin"] = true,
	["Level 5"] = true,
	["Level 4"] = true,
	["Level 3"] = false,
	["Level 2"] = false,
	["Level 1"] = false,
	["Level 0"] = false
	
}



local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
local door1Open = door1.Position + door1.CFrame.rightVector * -6.2
local door2Open = door2.Position + door1.CFrame.rightVector * 6.2
local door1Close = door1.Position + door1.CFrame.rightVector
local door2Close = door2.Position + door1.CFrame.rightVector
local canopen = true
local canclose = false
local db = false
local accessgranted = keycard.AccessGranted
local accessdenied = keycard.AccessDenied
local doorclose = keycard.DoorClose
local dooropen = keycard.DoorOpen

keycard.Touched:Connect(function(hit)
	if hit.Name == "Handle" and levels[hit.Parent.Name] and canopen == true and canclose == false then
		if db == false then
			db = true
			canopen = false
			accessgranted:Play()
			dooropen:Play()
			wait(0.2)
			local tween1 = tweenservice:Create(door1, tweeninfo, {Position = door1Open})
			local tween2 = tweenservice:Create(door2, tweeninfo, {Position = door2Open})
			door1.CanCollide = false
			door2.CanCollide = false
			db = false
			canclose = true
			tween1:Play()
			tween2:Play()
		end
	elseif hit.Name == "Handle" and levels[hit.Parent.Name] and canopen == false and canclose == true then
		if db == false then
			db = true
			canclose = false
			accessgranted:Play()
			doorclose:Play()
			wait(0.2)
			local tween1 = tweenservice:Create(door1, tweeninfo, {Position = door1Close})
			local tween2 = tweenservice:Create(door2, tweeninfo, {Position = door2Close})
			door1.CanCollide = true
			door2.CanCollide = true
			wait(0.8)
			db = false
			canopen = true
			tween1:Play()
			tween2:Play()
		end
	else
		if hit.Name == "Handle" then
			if db == false then
				db = true
				accessdenied:Play()
				wait(1)
				db = false
			end
		end
	end
end)

2 comments

0

why was this given a downvote? ;-;

0

Ye