Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Box that detect players?

Asked by 5 years ago

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)
0
tables my boy, TABLES AnotherPerson_999 28 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
Thanks a lot dude!, this is really useful! MArzalAlBuchariZ 33 — 5y
Ad

Answer this question