Problem with a door script

Hello devforum, I have a problem with a door script:
When a value is true you shouldnt be able to open it, but for some reason its like if the if statement didn’t work.

Script:

clickd.MouseClick:Connect(function(player)
	if script.Parent.Parent.Locked.Value == false then
		if opened.Value == false then
			sound:Play()
			opened.Value = true
			mainpart.CFrame = script.Parent.Parent.Door2.CFrame
		else
			sound:Play()
			opened.Value = false
			mainpart.CFrame = script.Parent.Parent.Door1.CFrame
		end
	elseif script.Parent.Parent.Locked.Value == true then
		print("Its locked")	
	end
end)

No errors in the output

Have you tried some more print debugging?

2 Likes

Is this in a server script, or a local.

1 Like

the script is in a server script

Can you share a picture of all the relevant stuff in the explorer? And is Locked a BoolValue?

2 Likes

Why did you make a player argument if you are not going to use it?

1 Like

What is the BoolValue ‘Locked’ a child of? You might be trying to reference it, and instead getting the .Locked value of a part.

Could you post an image of your explorer?

1 Like

Perhaps you should add a wait function for the player to have enough time to go through the door, also why are you checking the Locked value ? This may also be your problem as instead you could just use the opened value.

1 Like

I am going to use it later to make a key for the door

Because the player with the key can lock it and unlock it to toggle if other players who don’t have the key can open the door.

Then an error should pop up saying value is not a valid member of locked?

It is a bool value image

Could you post the entire script? What you’ve given us works fine.

Maybe you meant script.Parent.Parent.Opened.Value and not Opened.Value, Correct me if im wrong :+1:

Cause an if statement didn’t print errors for some reason, good luck

clickd.MouseClick:Connect(function(player)
	if script.Parent.Parent.Locked.Value == false then
		if script.Parent.Parent.Opened.Value == false then
			sound:Play()
			opened.Value = true
			mainpart.CFrame = script.Parent.Parent.Door2.CFrame
		else
			sound:Play()
			opened.Value = false
			mainpart.CFrame = script.Parent.Parent.Door1.CFrame
		end
	elseif script.Parent.Parent.Locked.Value == true then
		print("Its locked")	
	end
end)

Hope this helps