My function do not play simultaneous, why?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am working on a Replay module

  2. What is the issue? Include screenshots / videos if possible!
    I have a system wich insert a and insert all objects once in the viewportframe, i can update my camera CFrame and replay it, and i can save my Object’s CFrames in my Table. The issue is when i play it: The camera replay without issue, but when i for example replay my objects from workspace (for example my character) without using my second spawn function (see under), then my parts tween all, not at the same time, straight on the end CFrame, but if i toggle my second spawn function, and write it’s content in the other great function, i need to wait one minute, then all Part tween and make the mouvement i made, yes, but all not at the same time. If i use this in a RPG game, this would really look strange. What i am doing false?

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Here is any tutorial on a Replay system

This is my code (a snipped of this)

	spawn(function()
		for _,Object in pairs(ReplySystemArray.Objects) do
			if typeof(Object[1]) == "Instance" then
				for _,OCFrame in pairs(Object.CFrames) do
					spawn(function()
						local Name = Object[1].Name
						local object = ViewPortFrame[Name]
						local targetCFrame = OCFrame
						local ObjectCFrameTween = TweenService:Create(
							object,
							TweenInfo.new((1/#Object.CFrames)*75,Enum.EasingStyle.Linear,Enum.EasingDirection.In),
							{CFrame = targetCFrame}
						)
						
						ObjectCFrameTween:Play()
						ObjectCFrameTween.Completed:Wait()
					end)
				end
			end
		end
		ObjectCompleted = true
	end)

Hope you understand my problem

~~Eterna

2 Likes

I’m not sure how to use spawn(), but from what I’ve heard it’s better to use Coroutines: https://developer.roblox.com/en-us/api-reference/lua-docs/coroutine/index.html

It basically runs multiple functions at once.

1 Like

Spawn make the same as coroutines, but thanks anyway. This is why i am using Spawn. And yes, i know coroutines. Here is a link about spawn: Documentation - Roblox Creator Hub