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

Box that detect players?

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)

1 comment

0

tables my boy, TABLES

1 answer

✓ Accepted answer

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)

1 comment

0

Thanks a lot dude!, this is really useful!

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