Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Key opening door script not working, door not opening?

So i made a door with a key to open it and you pick up the key by stepping on it and then you put it in the door lock, like it touches the lock, and the door disappears. It was working before i deleted a script i made an "E to pick up tool script" which had no interference whatsoever with the door lock script. Now it does not work for anyone in game, please help heres the script:

--script start--

db = 0 function unlock(part)

if db == 0 then
	db = 1
	
	if part.Parent.Name == "Key - Level 1" and part.Parent:isA("Tool") then
		part.Parent:Destroy()			
		
		local doorParts = script.Parent.Parent:GetChildren()
		
		for i = 1, #doorParts do
			doorParts[i].Transparency = 1
			doorParts[i].CanCollide = false
			
			end
		end
	end		
end

db = 0

script.Parent.Touched:connect(unlock)

--script end--

2 comments

0

Are there any errors being thrown?

0

I am not getting any errors

1 answer

✓ Accepted answer

Try doing this:

local key = part.Parent:FindFirstChild("Key - Level 1")
if part ~= nil then

end

instead of what is on line 4.

Also make sure all of the children of the door are Parts so you can set the cancollide and transparency.

1 comment

0

Tysm! It works now

This discussion is preserved as it was. New answers, comments, and votes are closed.