#Randomize color only works for part 1, but not for part 2
38 messages · Page 1 of 1 (latest)
but he is using coroutine.wrap
that creates a new thread
and the code should continue
yeah well, i'll prefer task never used coroutine
ya i would also say use task.spawn(fucntion() instead
okay thank you
why?
** You are now Level 12! **
"Returns a function that resumes the coroutine each time it is called."
your calling the exact same function 2 times
So how do I use coroutines to make multiple tasks?
in the same time
and in same script
local Part1 = workspace:WaitForChild("Part1")
local Part2 = workspace:WaitForChild("Part2")
function ChangeColor(part)
while wait(.1) do
part.Color = Color3.new(math.random(0, 255), math.random(0, 255), math.random(0, 255))
end
end
coroutine.wrap(function()
ChangeColor(Part1)
end)()
coroutine.wrap(function()
ChangeColor(Part2)
end)()
this is how you would make it
np
as said earlier, task.spawn would work better here
task.spawn(ChangeColor, Part1)
task.spawn(ChangeColor, Part2)
Okay
But
When you pause a coroutine with coroutine.Resume
It stops and when you resume it so it starts again it does nothing cause the thread is "dead" any idea about how I fix that?
Nevermind
I managed to do something
Very very very cool
local Part1 = workspace:WaitForChild("Part1")
local Part2 = workspace:WaitForChild("Part2")
local Tasks = {}
Tasks.Resume = function(func, var)
return task.spawn(func, var)
end
Tasks.Cancel = function(ResumedTask)
task.cancel(ResumedTask)
end
local function ChangeColor(part)
while wait(.1) do
part.Color = Color3.new(math.random(0, 255), math.random(0, 255), math.random(0, 255))
end
end
local Task1 = Tasks.Resume(ChangeColor, Part1)
local Task2= Tasks.Resume(ChangeColor, Part2)
task.wait(5)
Tasks.Cancel(Task1)
Tasks.Cancel(Task2)
task.wait(3)
Tasks.Resume(ChangeColor, Part1)
Tasks.Resume(ChangeColor, Part2)