Struanmcd
|
  |
| Joined: 19 Sep 2008 |
| Total Posts: 369 |
|
|
| 22 Feb 2013 02:13 PM |
At the moment, I am building a model, which has a seat, and some buttons. I want the buttons to only be able to activate if the person is sat on the seat. The only problem is, the Touched event only fires once, so I put the question: Is it possible to do a "While touching do" script, or is it a giant monster of a script, which is too slow for any real applications.
The script would look something like this
function onTouched(hit) while hit do if button pressed //etc
Code above is in pseudo-code, but I want to know if it is hypothetically possible.
Thanks,
Struanmcd |
|
|
| Report Abuse |
|
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 22 Feb 2013 02:16 PM |
script.Parent.Touched:connect(function(hit) touching = true repeat wait() --code until touching == false end)
script.Parent.TouchEnded:connect(function() touching = false end) |
|
|
| Report Abuse |
|
|
Struanmcd
|
  |
| Joined: 19 Sep 2008 |
| Total Posts: 369 |
|
|
| 22 Feb 2013 02:18 PM |
I understand that. I never realised there was a TouchEnded event. Thanks for your help! |
|
|
| Report Abuse |
|
|
|
| 22 Feb 2013 03:08 PM |
^^
Problem with that. You need to create the touching variable before the functions. |
|
|
| Report Abuse |
|
|
cart6157
|
  |
| Joined: 28 Feb 2009 |
| Total Posts: 2194 |
|
|
| 22 Feb 2013 03:11 PM |
touching = false
script.Parent.Touched:connect(function(hit) touching = true repeat wait() --code until touching == false end)
script.Parent.TouchEnded:connect(function() touching = false end) |
|
|
| Report Abuse |
|
|
Struanmcd
|
  |
| Joined: 19 Sep 2008 |
| Total Posts: 369 |
|
|
| 22 Feb 2013 05:49 PM |
| It worked as I had the main script already written, so I just integrated it. But thanks for all the help! |
|
|
| Report Abuse |
|
|