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

How do you make something act like a pressure plate?

Asked by 8 years ago

I know how to do something when you step on a part (

function onTouch(hit)
-- hit is what I always put so I can do local player = game.Players:GetPlayerFromCharacter(hit.Parent)
-- Put code here bla bla bla
end
script.Parent.Touched:connect(onTouch)

) But I want to know how you can do something for the duration of while somebody is stepping on the part then do something else when they step off.

If you could help I would appreciate it!

1 answer

Log in to vote
0
Answered by
funyun 958 Moderation Voter
8 years ago

TouchEnded is an event of parts that you can add to the onTouch function like so:

function onTouchEnded(hit)
    --stuff
end

function onTouch(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    --stuff
    script.Parent.TouchEnded:connect(onTouchEnded)
end
script.Parent.Touched:connect(onTouch)

0
Thanks! I had heard about TouchEnded but didn't know if it would work in my situation. I will accept. jimborimbo 94 — 8y
0
This almost helped with my situation. However, how can I make it stop constantly spamming between touched and touchEnded whenever the player moves? Voltaicmimic 43 — 2y
Ad

Answer this question