So I am trying to make a program where if i am in the vicinity the doors will open, and if im not, the doors will close and the alarm will sound. The problem I am having is that if no one is around, it throws an error message that says trying to access a nil field. Here is my code :
local component = require("component")local colors = require "colors"
gpu = require("component").gpu
alarm = require("component").os_alarm
door = require("component").os_door
entity = require("component").os_entdetector
local w, h = gpu.getResolution()local delay -- sleep timelocal player -- list of playerswhiletruedo
os.sleep(2)if entity.scanPlayers(64)==truethen
scan = entity.scanPlayers(64)
name = scan[1].name
if name ~="sav"then
door.close()
alarm.activate()
print("Hello ".. scan[1].name)
os.sleep(2)
alarm.deactivate()elseif name =="sav"then
door.open()
alarm.deactivate()
print("Welcome Home Sav")
os.sleep(2)end
os.sleep(4)endend
This obviously doesnt work and just freezes the computer, any guidance on how to do something like, if someone is around then either open the door or close it based on who it is, if no one is around, than keep repeating the program until someone is. Any help would be appreciated,
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
So I am trying to make a program where if i am in the vicinity the doors will open, and if im not, the doors will close and the alarm will sound. The problem I am having is that if no one is around, it throws an error message that says trying to access a nil field. Here is my code :
This obviously doesnt work and just freezes the computer, any guidance on how to do something like, if someone is around then either open the door or close it based on who it is, if no one is around, than keep repeating the program until someone is. Any help would be appreciated,
Thank you
Link to post
Share on other sites