Keycard door not functional

Basically, if you touch a keycard reader (one of its children) the brickcolor of that part (that was touched) is supposed to turn green and flip a value of a bool value inside another model but it’s printing a error that the bool value is not a valid member of the model. Also tried using waitforchild but doesn’t work.

The error:

image

Where the bool value is stored:

image

Script for the touch part.

local Open = script.Parent.Parent.Parent:FindFirstChild("Door").OpenDoor -- This is where it errors

script.Parent.Touched:Connect(function(hit)
	    if hit.Parent:IsA("Tool") and hit.Parent.Name == "Royal Access Card"   then
		   Open.Value = true
		   script.Parent.BrickColor = BrickColor.new("Bright green")
		   wait(1)
		   Open.Value = false
		   script.Parent.BrickColor = BrickColor.new("Institutional white")
		
		 else wait(.5)
			
	    	Open.Value = false
			script.Parent.BrickColor = BrickColor.new("Really red")
			wait(1)
			script.Parent.BrickColor = BrickColor.new("Institutional white")
	end
end)

Can you explain the error or pin-point the error?

1 Like

Done, I posted an image of the output error.

local Open = script.Parent.Parent.Parent:FindFirstChild("Door").OpenDoor

Really curious how it turned into script.Parent.Parent.Parent, even if the bool value is one hierarchy away. Replace it with: script.Parent:FindFirstChild("OpenDoor") or script.Parent.OpenDoor

If the script is the child of the model, why do script.Parent.Parent.Parent? Shouldn’t it be script.Parent.OpenDoor

No, they both are seperate models.

No. Read the image again, I changed it

Oh, inside another model? Would you provide a screenshot over the entire hierarchy to the other model from the first one?

image

Both are stored inside a folder called Map.

Try using FindFirstAncestor("Map") instead of script.Parent.Parent... and then find the directory to the desired door model.

How do I use that? ( 30 characters)

Now they are no output errors but it doesn’t work…

Also, this is the moving door script.

local moving

local originalLeft = script.Parent.Left.PrimaryPart.CFrame
local originalRight = script.Parent.Right.PrimaryPart.CFrame

local function move()
	for i=1,30 do
		script.Parent.Left:SetPrimaryPartCFrame(originalLeft * CFrame.new(-9.2*(i/30),0,0))
		script.Parent.Right:SetPrimaryPartCFrame(originalRight * CFrame.new(9.6*(i/30),0,0))
		wait()
	end
	
	wait(2.5)
	
	for i=29,0,-1 do
		script.Parent.Left:SetPrimaryPartCFrame(originalLeft * CFrame.new(-9.2*(i/30),0,0))
		script.Parent.Right:SetPrimaryPartCFrame(originalRight * CFrame.new(9.6*(i/30),0,0))
		wait()
	end
	
	wait(1)
end

if script.Parent.OpenDoor.Value == true then
	    print("shshdhdh")
		moving = true
		move()
		moving = false
end

This line…
local Open = script.Parent.Parent.Parent:FindFirstChild("Door").OpenDoor

…would look like this:
local Open = script:FindFirstAncestor("Map"):FindFirstChild("Door").OpenDoor


More information here.


For the opening part, you are not connecting it to any event, rendering it not functional. Try not adding new replies, just edit your previous reply. Instead, I would connect to the Changed event on the value object to check if it turned true or not.

1 Like

Doesn’t work… :frowning: (30 characters)

Did you set a PrimaryPart?

30 char

Yes. The script is all good and i have tested it

And it doesnt even print (30 chars)

Mhmm… too low information, can you at least show me the explorer?
*all the object on door .

image

Yes of course. Here you go!