Door Opening Script broken after adding a lock system

Hello Scripters,

I hate bugs and errors and just as i added a lock system to my doors.

	doorModel.Sensor.Touched:Connect(function(hit)
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		
		if humanoid and doorModel:GetAttribute("Open") == false then
			if not locked then
				door.open(doorModel)
				
			elseif humanoid.Parent:FindFirstChild("Key") then
				doorModel.Lock:Destroy()
				humanoid.Parent.Key:Destroy()
				
				door.open(doorModel)
			end		
		end
	end)

I kept on getting the error, that im attempting index nil with FindFirstChild
(This happens no matter if i have the key tool equipped or not)

1 Like

Maybe try
local humanoid = hit.Parent:FindFirstChild("Humaoid") or nil

1 Like

I’m gonna assume it’s fixed as i didn’t got the error the first time again. Thanks for your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.