I want a function to run multiple times at the same time

This is my script that tweens part and in the end there is a for loop that loops through parts and tweens them. There is a function that I want to run multiple time instantly. There is a video showcasing it

local TweenService = game:GetService("TweenService")
local Objects = game.Workspace.PartFolder:GetChildren()

local ColorTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, 0)
local SizeTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, 0)

local function Tweener(part)
	local GrayColorTween = TweenService:Create(part , ColorTweenInfo, { Color = Color3.new(0.356863, 0.364706, 0.411765)})
	local BlackColorTween = TweenService:Create(part , ColorTweenInfo, { Color = Color3.new(0.101961, 0.101961, 0.101961)})

	local BigSizeTween = TweenService:Create(part , SizeTweenInfo, { Size = Vector3.new(8, 1, 8) })
	local SmallSizeTween = TweenService:Create(part , SizeTweenInfo, { Size = Vector3.new(2,1,2) })

	BlackColorTween:Play()
	wait(1)
	GrayColorTween:Play()
	wait(1)
	SmallSizeTween:Play()
	wait(2)
	BigSizeTween:Play()
end

wait(5)

for index, value in pairs(Objects) do
	Tweener(Objects[index]) -- I want this function to run multiple times at the same time
end

There are three parts that don’t get tweened at the same time. I want them to get tweened at the same time

1 Like

You can use task.spawn() from the task library to run multiple yielding functions simultaneously.

At the bottom of your script, try changing the for loop to:

for index, value in pairs(Objects) do
	task.spawn(function()
       Tweener(Objects[index]) 
    end)
end
1 Like

use task.spawn(Tweener,Objects[index]) to create a new thread for each function

for index, value in pairs(Objects) do
	task.spawn(Tweener,Objects[index])
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.