|
| 07 Sep 2013 08:37 AM |
local brick = script.Parent
brick.Touched:connect(function (hit) if hit.Name == "Part" then while hit.Name == "Part" do print("Still Touching") wait() end end end)
Obviously, this isn't going the way I would want it. However, is there some way to have the Touched event fire if "Part" is still touching the "brick" so that if Part is touching Brick, it will print "Still Touching" until Part moves or gets destroyed? |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2013 08:41 AM |
Best way is to have a boolvalue, that changes to true when touched. And false when TouchEnded. From there assuming this script is inside the boolvalue
local parent = script.Parent parent.Changed:connect(function(value) if value == true then repeat print('Still touching') wait() until value == false else print('Touch ended, change the boolvalue yourself') end end ) |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2013 08:43 AM |
This might work...
brick.Touched:connect(function(part) -- Touching now while (brick.TouchEnded:wait() ~= part) do end -- Stopped touching end) |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2013 08:44 AM |
| Aye, my method does work. Tested it |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2013 08:55 AM |
It works, although I still have a question. I modified it so you can see what I did to it if I did anything wrong.
local brick = script.Parent
brick.Touched:connect(function (hit) print("Still Touching") while (script.Parent.TouchEnded:wait() ~= hit) do end print("Done touching") end)
I dropped a Part into Brick and it prints:
> Still Touching > Done Touching > Still Touching > Done Touching > Still Touching
only repeated a few times, but it prints Done Touching when it's still touching. Did I do something wrong? Or is there still another method? |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2013 08:59 AM |
I don't know, sorry. I never have actually used the TouchEnded method for anything. I'll try to rewrite it to be a bit more effective...hopefully:
local brick = script.Parent local touching = {}
brick.Touched:connect(function(part) touching[part] = true print("Touching") while (touching[part]) do -- While touching... Wait() end print("Stopped touching") end)
brick.TouchEnded:connect(function(part) touching[part] = nil end) |
|
|
| Report Abuse |
|
|