|
| 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
|
  |
| Joined: 26 Mar 2010 |
| Total Posts: 869 |
|
| |
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 23 Sep 2012 05:42 PM |
| That's just part of a script. Bump. |
|
|
| Report Abuse |
|
|
| |
|
Flame6264
|
  |
| Joined: 06 Mar 2012 |
| Total Posts: 3379 |
|
| |
|
UFAIL2
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 6905 |
|
|
| 23 Sep 2012 07:26 PM |
| Has nobody heard of the .TouchEnded event? |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2012 07:42 PM |
| Yes, but in this case is if you touch a brick, it ends. |
|
|
| Report Abuse |
|
|