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

How do you make something act like a pressure plate?

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

✓ Accepted answer

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)

2 comments

0

Thanks! I had heard about TouchEnded but didn't know if it would work in my situation. I will accept.

0

This almost helped with my situation. However, how can I make it stop constantly spamming between touched and touchEnded whenever the player moves?

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