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: How would I thread this correctly?

Previous Thread :: Next Thread 
Aalok is not online. Aalok
Joined: 20 Jun 2014
Total Posts: 1136
16 Feb 2015 06:53 PM
So I have two for loops, one iterating through a table and one numerical. I want to loop both of these using a while loop, and have both of the for loops running at the same time. How would I do this?

spawn(function()
while char do
p1, p2 = char.Torso.Position, floater.Position
local dist = (p1 - p2).magnitude
for i = 0, math.pi * 100, 0.05 do
weld.C0 = CFrame.new(3.5 * math.sin(i), math.sin(tick()) * 1.5, 2.5 * math.cos(i))
weld.C1 = CFrame.Angles(math.cos(i), math.cos(i), 0)
for i, v in pairs(rainbow) do
floater.BrickColor = v
s.RunService.RenderStepped:wait()
end
s.RunService.RenderStepped:wait()
end
end
end)
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
16 Feb 2015 07:27 PM
If they have to be nested, then you can't have them running simultaneously.
Report Abuse
Aalok is not online. Aalok
Joined: 20 Jun 2014
Total Posts: 1136
16 Feb 2015 07:29 PM
Aw well..
Report Abuse
Aalok is not online. Aalok
Joined: 20 Jun 2014
Total Posts: 1136
16 Feb 2015 07:39 PM
Are there workarounds?
Report Abuse
Aalok is not online. Aalok
Joined: 20 Jun 2014
Total Posts: 1136
16 Feb 2015 08:17 PM
Wait I had them nested? WOOPS!

--[[
PRISM: Protective Risk Identifier System
--]]

local s = {
Players = game:getService('Players'),
Workspace = game:getService('Workspace'),
RunService = game:getService('RunService');
}
local plr = s.Players.LocalPlayer
local char = plr.Character
local p1, p2;
local rainbow = {
BrickColor.new('Really red'), BrickColor.new('Dusty rose'), BrickColor.new('Tr. Red'), BrickColor.new('Medium red'), BrickColor.new('Light pink'), BrickColor.new('Tr. Flu. Red'), BrickColor.new('Light purple'), BrickColor.new('Tr. Medi. reddish violet'), BrickColor.new('Light reddish violet'), BrickColor.new('Pastel orange'), BrickColor.new('Brick yellow'), BrickColor.new('Lig. Yellowich orange'), BrickColor.new('Light orange'), BrickColor.new('Nougat'), BrickColor.new('Light orange brown'), BrickColor.new('Bright orange'), BrickColor.new('Warm yellowish orange'), BrickColor.new('Light yellow'), BrickColor.new('Tr. Flu. Yellow'), BrickColor.new('New Yeller'), BrickColor.new('Tr. Flu. Green'), BrickColor.new('Lig. yellowish green'), BrickColor.new('Medium green'), BrickColor.new('Tr. Green'), BrickColor.new('Bright green'), BrickColor.new('Dark green'), BrickColor.new('Sand green'), BrickColor.new('Pastel green'), BrickColor.new('Light bluish green'), BrickColor.new('Turquoise'), BrickColor.new('Dove blue'), BrickColor.new('Medium blue'), BrickColor.new('Deep blue'), BrickColor.new('Really blue'), BrickColor.new('Navy blue'), BrickColor.new('Medium lilac'), BrickColor.new('Bright violet'), BrickColor.new('Magenta'), BrickColor.new('Lavender'), BrickColor.new('Sand violet'), BrickColor.new('Pastel orange'), BrickColor.new('Light reddish violet'), BrickColor.new('Tr. Medi. reddish violet'), BrickColor.new('Light pink'), BrickColor.new('Medium red'), BrickColor.new('Tr. Red'), BrickColor.new('Dusty rose')
}

local floater = Instance.new('Part', char)
floater.formFactor = Enum.FormFactor.Custom
floater.Size = Vector3.new(1.5, 1.5, 1.5)
floater.Anchored = false
floater.Transparency = 0.4
floater.Material = Enum.Material.SmoothPlastic
floater.TopSurface, floater.BottomSurface = Enum.SurfaceType.Smooth, Enum.SurfaceType.Smooth
floater.CanCollide = false
local weld = Instance.new('Weld', floater)
weld.Part0 = floater
weld.Part1 = char.Torso
spawn(function()
while char do
p1, p2 = char.Torso.Position, floater.Position
local dist = (p1 - p2).magnitude
for i = 0, math.pi * 100, 0.05 do
weld.C0 = CFrame.new(3.5 * math.sin(i), math.sin(tick()) * 1.5, 2.5 * math.cos(i))
weld.C1 = CFrame.Angles(math.cos(i), math.cos(i), 0)
s.RunService.RenderStepped:wait()
end
for i, v in pairs(rainbow) do
floater.BrickColor = v
s.RunService.RenderStepped:wait()
end
end
end)
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
16 Feb 2015 09:20 PM
If they aren't nested then you can simply use coroutines.

coroutine.resume(coroutine.create(function()
for i = 0, math.pi * 100, 0.05 do
weld.C0 = CFrame.new(3.5 * math.sin(i), math.sin(tick()) * 1.5, 2.5 * math.cos(i))
weld.C1 = CFrame.Angles(math.cos(i), math.cos(i), 0)
s.RunService.RenderStepped:wait()
end end))
coroutine.resume(coroutine.create(function()
for i, v in pairs(rainbow) do
floater.BrickColor = v
s.RunService.RenderStepped:wait()
end 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