|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|