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 » Scripters
Home Search
 

Re: Roblox for loop waits until function is done

Previous Thread :: Next Thread 
Klauensprung is not online. Klauensprung
Joined: 10 Mar 2010
Total Posts: 94
23 May 2016 08:38 AM
Hello guys,
I wanted to know if it is possible to run a loop and in this loop a function
but the loop should NOY wait until the function is done.
The code is the following :

( When I make things transparent with the trans function, the script freezes until this is done )

print 'Hello world!'
local myNum = script.Parent.Config.RoomNr.Value
local Mode = script.Parent.Config.Mode

for index, child in pairs(script.Parent:GetChildren()) do
if(child.Name == "H1" or child.Name == "H2")then

child.Touched:connect(function(otherPart)
print("Connecting")
if(otherPart.Name == "Handle" and otherPart:findFirstChild("RoomNr") and otherPart.RoomNr.Value == myNum) then

if(Mode.Value == 0) then
activate()
end

--//Declare open here




end
end)



end
end

function trans(nr, part)

if(nr == 2) then


while part.Transparency > 0 do
part.Transparency = part.Transparency - 0.05
print("Visibling")
wait(0.1)
end


elseif(nr == 1) then



while part.Transparency < 1 do
part.Transparency = part.Transparency + 0.05
wait(0.1)

end

end

end


function deactivate()

Mode.Value = 2

for index, child in pairs(script.Parent:GetChildren()) do
if(child.ClassName == "Part" or child.ClassName == "UnionOperation")then
child.Transparency = 1
print("Shooting")
trans(2,child) -- < This one
child.CanCollide = true
end








end




local X1 = script.Parent.G
local X2 = script.Parent.G2

X1.PointLight:Destroy()
X2.PointLight:Destroy()



Mode.Value = 0

end

function activate()

Mode.Value = 1


for index, child in pairs(script.Parent:GetChildren()) do
if(child.ClassName == "Part" or child.ClassName == "UnionOperation")then
child.CanCollide = false
trans(1,child) -- < This one
end

end

wait(2)








local X1 = script.Parent.G
local X2 = script.Parent.G2

local M1 = game.Lighting.PointLight:Clone()
M1.Color = X1.BrickColor.Color

local M2 = game.Lighting.PointLight:Clone()
M2.Color = X2.BrickColor.Color

local W1 = Color3.new(255,255,255)
local R1 = Color3.new(0,255,0)


M1.Parent = X1
M2.Parent = X2

wait(0.5)
deactivate()


end



Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
23 May 2016 08:45 AM
Oh god that code XD

Anyways, what you want are Coroutines.

local newThread = coroutine.wrap(function()
print("I'm doing a function thing!")
end)

while wait(1) do
newThread()
end

Something like that ^
Report Abuse
Wayne_Gretzky is not online. Wayne_Gretzky
Joined: 03 Apr 2008
Total Posts: 78011
23 May 2016 08:56 AM
I don't rlly think this is one for coroutines
You'd want to make a table of everything you want transparent, and in the loop do all of them at the same time
Report Abuse
Klauensprung is not online. Klauensprung
Joined: 10 Mar 2010
Total Posts: 94
23 May 2016 09:57 AM
Thank you, it worked like a charme with the corutines.
Having a table and looping will restult in the same. Wont skip the wait obviosuly, but thanks for your contribution !
Report Abuse
Wayne_Gretzky is not online. Wayne_Gretzky
Joined: 03 Apr 2008
Total Posts: 78011
23 May 2016 10:50 AM
its unnecessarily harder on the processor tho

#code R+ | local cat = { lives = 9, makeNoise = function() print("meow") end }
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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