So, I wanted to make a box that will detect if there's any player close to the door by making a go-through transparent box around the door, it worked. But the problem is that, I don't know how to make sure that after the door opened and the player left the inside of the box (stopped hitting the box), the door will close. open() is a function to open the door and close() is a function to close the door. I don't really think including the full function down below will really affect anything since it's just TweenService.
door = game.Workspace.door1 box = script.Parent function Ontouch(hit) open() --?? close() end script.Parent.Touched:Connect(Ontouch)
This should work, but don't forget to check if the part is a player
You have to use TouchEnded
Here's an example:
local function onTouch(part) print("Touch started: " .. part.Name) end local function onTouchEnded(part) print("Touch ended: " .. part.Name) end part.Touched:Connect(onTouch) part.TouchEnded:Connect(onTouchEnded)
Your script should be something like
door = game.Workspace.door1 box = script.Parent function Ontouch(hit) --Here goes your player touch check! open() end function onTouchEnded(hit) --Here goes your player touch check! close() end script.Parent.Touched:Connect(OnTouch) script.Parent.TouchEnded:Connect(onTouchEnded)