generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

While Touching Do

Previous Thread :: Next Thread 
Jonah13249 is not online. Jonah13249
Joined: 09 Oct 2009
Total Posts: 2105
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
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
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
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
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
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
07 Sep 2013 08:44 AM
Aye, my method does work. Tested it
Report Abuse
Jonah13249 is not online. Jonah13249
Joined: 09 Oct 2009
Total Posts: 2105
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
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image