Help with script

Hello guys Ranger here. So here i wrote a script that is a owner only door… It is not working for me. If possible I would like you to test it. Just to know or at least do a code review. So please tell me where i am wrong.

-- list of account names allowed to go through the door. 
permission = {"USERNAME HERE"}--Put your friends name's here. You can add more.

function checkOkToLetIn(name) 
  for i = 1,#permission do 
	if (string.upper(name) == string.upper(permission[i])) then return true end 
return false 

local Door = script.Parent

function onTouched(hit) 
  print("Door Hit") 
  local human = hit.Parent:findFirstChild("Humanoid") 
 if (human ~= nil ) then 
	-- a human has touched this door! 
	print("Human touched door") 
	-- test the human's name against the permission list 
	if (checkOkToLetIn(human.Parent.Name)) then 
		print("Human passed test") 
		Door.Transparency = 0.7 
		Door.CanCollide = false 
		wait(1) -- this is how long the door is open 
		Door.CanCollide = true 
		Door.Transparency = 0 
	    else human.Health= 0 -- delete this line of you want a non-killing VIP door 

Please tell me where I am wrong. If it is right then I will try doing it again thank you!

Hi. Your code is all good, but you need to connect the onTouched function to a Touched event like so:


Although not necessary, you should use :FindFirstChild() instead. Since :findFirstChild() is deprecated.

1 Like

Thank you all for the help. :slight_smile:

1 Like