How To Synchronize Tweens?

I’m making a game where you can place down objects. Some of these objects move and right now they move based on when you placed them. The objects are not synched because they are not placed at the same second.

To fix this problem I tried to use os.time() and modulus to sync them, but that didn’t work. Another idea that I had in mind was to create a boolvalue that became true when it was time to move the spikes, but I made it so that you can customize the timing of the spike so I would need dozens of boolvalues and I don’t want to do that.

I was wondering if anyone knows how to synchronize the moving objects.

1 Like

I would guess the best way to do this would be to have one loop that loops through every spike block in the game and updates it at once, as compared to individually for each spike block/player.

Example:

local tweenService = game:GetService("TweenService")
for i, v in pairs(workspace.Spikes) do
      local spikeTween = tweenService:Create(v.Spike, TweenInfo.new(0.5), {Position = Vector3.new(x, y, z)})
      spikeTween:Play()
end

wrote in devforum so dont copy and paste use for general idea

2 Likes

I am assuming you are CFraming these using tweenservice. I suggest you create a table and put all of the spike objects into it. create a Instance.new(“CFrameValue”) and call tween service on just the cframe value. In this code I am using tween service that loops and will go up and down which looks like what you are wanting to achieve. Storing the basecf is a good idea because in this method you could angle the spike brick or even turn it upside down and it would still work. I’m not sure if this is what you are looking for but hopefully it can give you another option.

6 Likes