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
 

Re: Touched ends a while true do?

Previous Thread :: Next Thread 
blackboy167thst is not online. blackboy167thst
Joined: 22 Jul 2011
Total Posts: 2468
23 Sep 2012 05:30 PM
How do I make it if the player touches a part it ends the while true do currently running?
Report Abuse
nairod7 is not online. nairod7
Joined: 26 Mar 2010
Total Posts: 869
23 Sep 2012 05:32 PM
Use the "break" keyword.
Report Abuse
blackboy167thst is not online. blackboy167thst
Joined: 22 Jul 2011
Total Posts: 2468
23 Sep 2012 05:32 PM
Ah, thanks.
Report Abuse
L2000 is not online. L2000
Joined: 03 Apr 2008
Total Posts: 77448
23 Sep 2012 05:33 PM
Use a variable. Then, inside the touched events, set it to true or false, and run the loop in the first touch (If it is not already running).

So, basically, your code would be:

local part = script.Parent
local touched = false
part.Touched:connect(function(hit)

-- Check if it's a player
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then

-- Set touched to true
touched = true

-- Run the while loop
while touched do
-- Code
end

end
end)

part.TouchEnded:connect(function()
touched = false -- End the loop
end)
Report Abuse
julienmauriemort is not online. julienmauriemort
Joined: 09 May 2009
Total Posts: 21560
23 Sep 2012 05:34 PM
run = true

while run do
(insert code here)
end

function hit(p)
local h = p.Parent:findFirstChild("Humanoid")
if h ~= nil then
run = false
end
end

script.Parent.Touched:connect(hit)
Report Abuse
blackboy167thst is not online. blackboy167thst
Joined: 22 Jul 2011
Total Posts: 2468
23 Sep 2012 05:34 PM
So in this case. I want it so that if the player touches a brick, the while true do will break, how do i do that?

while true do
if player.Character.Head ~= nil then
wait(0.1)
local brick = Instance.new("Part")
brick.Parent = game.Workspace
brick.Size = Vector3.new(2, 2, 2)
brick.Position = Vector3.new(player.Character.Head.Position.x, player.Character.Head.Position.y + 15, player.Character.Head.Position.z)
brick.BrickColor = BrickColor.new("Lime green")
brick.CanCollide = false
brick.Touched:connect(function(kill)
wait(0.1)
end
Report Abuse
blackboy167thst is not online. blackboy167thst
Joined: 22 Jul 2011
Total Posts: 2468
23 Sep 2012 05:42 PM
That's just part of a script. Bump.
Report Abuse
blackboy167thst is not online. blackboy167thst
Joined: 22 Jul 2011
Total Posts: 2468
23 Sep 2012 05:46 PM
Never mind. Fixed it :)
Report Abuse
Flame6264 is not online. Flame6264
Joined: 06 Mar 2012
Total Posts: 3379
23 Sep 2012 06:29 PM
!
















1
1

1
2
12321
321
Report Abuse
UFAIL2 is online. UFAIL2
Joined: 14 Aug 2010
Total Posts: 6905
23 Sep 2012 07:26 PM
Has nobody heard of the .TouchEnded event?
Report Abuse
blackboy167thst is not online. blackboy167thst
Joined: 22 Jul 2011
Total Posts: 2468
23 Sep 2012 07:42 PM
Yes, but in this case is if you touch a brick, it ends.
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