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: while touching a brick,

Previous Thread :: Next Thread 
HashtagLua is not online. HashtagLua
Joined: 17 Oct 2013
Total Posts: 91
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
IAmTheRolo is not online. IAmTheRolo
Joined: 12 Nov 2013
Total Posts: 859
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
HashtagLua is not online. HashtagLua
Joined: 17 Oct 2013
Total Posts: 91
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
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
05 May 2014 08:27 PM
You can use Touched and TouchEnded instead
Report Abuse
HashtagLua is not online. HashtagLua
Joined: 17 Oct 2013
Total Posts: 91
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
HashtagLua is not online. HashtagLua
Joined: 17 Oct 2013
Total Posts: 91
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 is not online. 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
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
06 May 2014 08:24 AM
Start a function when it's 'Touched', and end it with 'TouchEnded.
Report Abuse
vlekje513 is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 May 2014 08:50 AM
Mine doesn't overcomplicate it for the OP with tables.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. 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
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