I need help with a key how would i make one?

You can write your topic however you want, but you need to answer these questions:

  1. **What do you want to achieve?**I want it so when a player touches the door it does not open but when they have a key it’ll open.

  2. **What is the issue?**No screenshots

  3. What solutions have you tried so far? None and I can’t go on yt until Saturday and Friday

Heres the script it’ll open for player and key so please help

local door = script.Parent
local key = game.StarterPack.Key.Handle.Main

door.Touched:Connect(function()
	if key then
		script.Parent.Transparency = 1
		script.Parent.CanCollide = false
	end
end)
local door = script.Parent

door.Touched:Connect(function(player)
	if player.Parent:FindFirstChild("Key") then
		door.Transparency = 1
		door.CanCollide = false
	end
end)

The player parameter might be a bit confusing, instead I suggest to do something like this:

local door = script.Parent

local function onTouched(object) -- object which touched
   local key = object:FindFirstAncestor("Key") --  gets the first ancestor called "Key"
   if key and key:IsA("Tool") then -- if the key is found and it is a tool then
      door.Transparency, door.CanCollide = 1, false -- make the door transparent and the door not collidable
   end
end

door.Touched:Connect(onTouched)

If you want to make the door only open for a few seconds I suggest to add a debounce also known as a db what a db does is stop the player from opening it again while its open, which might glitch the script.

local door = script.Parent

do
   local db = false -- when its true the script wont run

   local function onTouched(object) -- object which touched
      if not db then return end -- if db is false then the script wont run
      local key = object:FindFirstAncestor("Key") --  gets the first ancestor called "Key"

      if key and key:IsA("Tool") then -- if the key is found and it is a tool then
         door.Transparency, door.CanCollide = 1, false -- make the door transparent and the door not collidable
      end
   end
end

door.Touched:Connect(onTouched)

Does it have to be in the key or the door

Thank you this helped a lot im making a pirate based game like piggy but a pirate.