Door script not continuing for some reason

So, I’m making a keycard system based door.
[coding hell warning]

local prompt = script.Parent
local doorModel = script.Parent.Parent.Parent.Parent.Parent
local door1 = doorModel.Doors.Door1
-- > SETUP < --

local door2 = doorModel.Doors.Door2
local doorT1 = doorModel.Doors.TargetD1
local doorT2 = doorModel.Doors.TargetD2

local closePos1 = doorModel.Doors.Door1.Position
local closePos2 = doorModel.Doors.Door2.Position


local keycardLight1 = doorModel.KeycardReader1.Func.KeycardLight
local keycardLight2 = doorModel.KeycardReader2.Func.KeycardLight

local cards = {
	["LightAccessKeycard"] = true,
	["MediumAccessKeycard"] = true,
	["HeavyAccessKeycard"] = true,
	["HostileHackBypasser"] = true,
	["AdminBypasser"] = true;
	
}

-- > TWEENING < --

local tweenService = game:GetService("TweenService")
local goal1 = {}
local goal2 = {}
local goalclose1 = {}
local goalclose2 = {}

goal1.Position = doorT1.Position
goal2.Position = doorT2.Position
goalclose1.Position = closePos1
goalclose2.Position = closePos2

local InfoD1 = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0)
local InfoD2 = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0)

local tweenD1 = tweenService:Create(door1, InfoD1, goal1)
local tweenD2 = tweenService:Create(door2, InfoD1, goal2)

local tweenClse1 = tweenService:Create(door1, InfoD1, goal1)
local tweenClse2 = tweenService:Create(door2, InfoD1, goal2)

-- > CODE < --

prompt.Triggered:Connect(function(plr)
	local debounce = doorModel.IsMoving.Value
	local char = plr.Character or plr.CharacterAdded:Wait()
	print("Debounce check.")
	if debounce then return end
	print("No debounce.")
	debounce = true
	local plrBackpackContent = plr.Backpack:GetChildren()
	print("Children obtained.")
	for i,tool in pairs(plrBackpackContent) do
		print(tool.Name)
		if tool:IsA("Tool") then
			if table.find(plrBackpackContent,cards) then
				print("Checking tools..")
				for i,card in pairs(cards) do
					if card then
						print("Success!")
						keycardLight1.Color = Color3.fromRGB(26, 255, 0)
						keycardLight2.Color = Color3.fromRGB(26, 255, 0)
						tweenD1:Play()
						tweenD2:Play()
						tweenD1.Completed:Wait()
						tweenD2.Completed:Wait()
						keycardLight1.Color = Color3.fromRGB(255, 0, 4)
						keycardLight2.Color = Color3.fromRGB(255, 0, 4)
						task.wait(2)
						tweenClse1:Play()
						tweenClse2:Play()
						tweenClse1.Completed:Wait()
						tweenClse2.Completed:Wait()
						debounce = false
					else
						print("Invalid card inserted by: "..plr.Name)
					end

		end

			end
		end
	end
	
	
end)

However, after this part:

print(tool.Name)

It just doesn’t continue after that. I do not know why. Could anyone help out?

1 Like

after that line it says: if tool:IsA("Tool") then
so your script thinks the tool variable is not a tool.

also your script doesn’t make sense you’re looking through plrbackpack contents, the children of the players’ backpack, for a table you created inside of the script, it couldn’t possibly be inside of the player’s backpack because it is a table not an instance.
if table.find(plrBackpackContent,cards) then

if you’re trying to look if the table cards has a key that has the same name as the tool.
do:

if cards[tool.Name] ~= nil then --evaluates to true if cards[tool.Name] is not nil

also please, add debounce as a value in the script, why is it a bool value :sob: (crying from coding hell not laughing, for some reason people think crying is laughing wth)

also why the hell are you looping through each item in cards, to check if they are all true, and if one is false, then it is an invalid card?
so what if a player inserts card1, so card1 gets set to true assumed, but card2 is still false, because it hasn’t been inserted yet, so it prints invalid card???

what is your goal? this is XY problem, instead of saying : “how to do this” you ask “how do I make my solution work, and I haven’t thought about it actually being overcomplicated.”

what are you trying to achieve?
what is the point of the script?

edit: if you could answer what your goal is, I could find a simpler way of achieving it.

check the character and backpack for one of the cards in the script, if its marked as true, proceed with the script, else, run some other code.

the reason the debounce isnt in the script is because there are two doors, hence the two tweens.