|
| 05 May 2014 08:18 PM |
How do I do something for every second someone is touching a brick? I've always wondered this.
Time is a tool you can put on a wall, or wear it on your rizd. |
|
|
| Report Abuse |
|
|
|
| 05 May 2014 08:24 PM |
Region3.
http://wiki.roblox.com/index.php?title=Region3 http://wiki.roblox.com/index.php?title=FindPartsInRegion3 |
|
|
| Report Abuse |
|
|
|
| 05 May 2014 08:24 PM |
Thanks.
Time is a tool you can put on a wall, or wear it on your rizd. |
|
|
| Report Abuse |
|
|
|
| 05 May 2014 08:27 PM |
| You can use Touched and TouchEnded instead |
|
|
| Report Abuse |
|
|
|
| 06 May 2014 07:11 AM |
Okay, with FindPartsInRegion3, I still don't understand how to repeat something until they aren't in the Region3.
Time is a tool you can put on a wall, or wear it on your rizd. |
|
|
| Report Abuse |
|
|
|
| 06 May 2014 07:13 AM |
Wait, would this work to repeat it every one second?:
local Point1 = Vector3.new(0,0,0) local Point2 = Vector3.new(10,10,10) local Region = Region3.new(Point1,Point2) for _,Part in pairs(game.Workspace:FindPartsInRegion3(Region,nil,100)) do print(Part.Name) Part.Value = Part.Value+1 wait(1) end
Time is a tool you can put on a wall, or wear it on your rizd. |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 06 May 2014 08:22 AM |
Region3 is a waste of effeciency and lagg, use TouchEnded
|
|
|
| Report Abuse |
|
|
|
| 06 May 2014 08:24 AM |
| Start a function when it's 'Touched', and end it with 'TouchEnded. |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 06 May 2014 08:39 AM |
Part = script.Parent Touching = {}
while wait(1) do for _, p in pairs(Touching) do if p.Character and p.Character:FindFirstChild("Humanoid") then p.Character:FindFirstChild("Humanoid").Health = p.Character:FindFirstChild("Humanoid").MaxHealth / 30 end end end
Part.Touched:connect(function(Hit) Player = game.Players:GetPlayerFromCharacter(Hit.Parent) if Player and Player.Character then table.insert(Touching, Player) end end)
Part.TouchEnded:connect(function(Hit) Player = game.Players:GetPlayerFromCharacter(Hit.Parent) if Player and Player.Character then table.remove(Touching, Player) end end)
Thats how I would do it. |
|
|
| Report Abuse |
|
|
|
| 06 May 2014 08:43 AM |
T = 1 --Repeat every T seconds
script.Parent.Touched:connect(function(h) if h.Parent:FindFirstChild("Humanoid") then if h.Parent:FindFirstChild("Bo")==nil then B = Instance.new("BoolValue", h.Parent) B.Name = "Bo" B.Value = true end while h.Parent.Bo.Value == true do --Stuff wait(T) end end end)
script.Parent.TouchEnded:connect(function() if h.Parent:FindFirstChild("Bo") then h.Parent.Bo.Value = false end end)
Should work :D |
|
|
| Report Abuse |
|
|
|
| 06 May 2014 08:44 AM |
Revised
T = 1 --Repeat every T seconds
script.Parent.Touched:connect(function(h) if h.Parent:FindFirstChild("Humanoid") then if h.Parent:FindFirstChild("Bo")==nil then local B = Instance.new("BoolValue", h.Parent) B.Name = "Bo" B.Value = true end while h.Parent.Bo.Value == true do --Stuff wait(T) end end end)
script.Parent.TouchEnded:connect(function() if h.Parent:FindFirstChild("Bo") then h.Parent.Bo.Value = false end end)
Should work :D
I forgot to make B local. |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 06 May 2014 08:48 AM |
| I like mine more, but dang i forgot a time variable. I love variables. |
|
|
| Report Abuse |
|
|
|
| 06 May 2014 08:50 AM |
| Mine doesn't overcomplicate it for the OP with tables. |
|
|
| Report Abuse |
|
|
|
| 06 May 2014 08:52 AM |
Besides Vlek I just noticed yours would keep repeating when they step off XD
table.remove(Touching, Player)
You tell me what's wrong with that (feel free to check the wiki...) |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 06 May 2014 08:55 AM |
I was already afraid of that. But still, mine easily fires while the other parts make sure its running good, thats just the code.
They failed this time though. |
|
|
| Report Abuse |
|
|