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

How to I open a door with key?

Hi I am making an open door with key can someone tell me were I went wrong please?


function ontouch(hit)

 local Doorkey = hit:findFirstChild("Doorkey") -- Finding the Humanoid in Card Tool
 if Doorkey then -- if Key Touched Then >>
  script.Parent.Transparency = 0.4
  script.Parent.CanCollide = false
  script.Parent.Sign.BrickColor = BrickColor.Green
  wait(5)-- time for door
  script.Parent.Transparency = 0
  script.Parent.CanCollide = true
  script.Parent.Sign.BrickColor = BrickColor.White
 end
end
script.Parent.Touched:Connect

2 answers

✓ Accepted answer

Howdy!

You didn't connect the trigger with the function itself. Essentially, you've got a gun without a trigger. Try what I have below.

function ontouch(hit)

local Doorkey = hit:FindFirstChild("Doorkey") -- Finding the Humanoid in Card Tool
	if Doorkey then -- if Key Touched Then >>
		script.Parent.Transparency = 0.4
		script.Parent.CanCollide = false
		script.Parent.Sign.BrickColor = BrickColor.Green
		wait(5)-- time for door
		script.Parent.Transparency = 0
		script.Parent.CanCollide = true
		script.Parent.Sign.BrickColor = BrickColor.White
	end
end
script.Parent.Touched:Connect(ontouch)

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

3 comments

0

Oh, I don’t see what you mean by try what I have below

0

Look at the script I have below my words.

0

Ohhhhhhhhhhhh tysm

Well Mr.Snooxy, making a key to open a door is quite simple. You just need to put that if the key touched the door, (onTouch Event) Then the door will become more transparent and CanCollide will be set to false in the code, watch:

script.Parent.Touched:connect(function(p)
      if p.Parent.Name == "Key Name Here" then
           script.Parent.Transparency = 0.5
           script.Parent.CanCollide = false
           wait (1)
           script.Parent.Transparency = 0
           script.Parent.CanCollide = true
   end
end)

1 comment

0

If this did not help, I am sorry and please contact me

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