Problems with tweening

I am making checkpoint systems and when a player touches a checkpoint it will do little tweens downward and rotate. It works, however, when there are two players that touch the same checkpoint before the animation of the one who first touched it finished it breaks.
This is the entirety of the checkpoint script (Scroll down to comment "Checkpoint animation for the tween part)


–Made by Its4Realzies
for i, child in ipairs (script.Parent:GetChildren())do
if child.ClassName == ‘Part’ then
child.Touched:connect(function(hit)
–Check for Player
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
–Check for Player’s humanoid and that its alive
local humanoid = hit.Parent:FindFirstChild(“Humanoid”)
if not humanoid or humanoid.Health <= 0 then return end

		--Difines leaderstats
		local leaderstats = player:FindFirstChild("leaderstats")
		if not leaderstats then return end
		local checkpointStat = leaderstats:FindFirstChild("Stage")
		local deathStat = leaderstats:FindFirstChild("Deaths")
		
		if child.Name ~= "Reset" then
			--Checks if its the next checkpoint thats been touched 
			local checkpointNumber = string.gsub(child.Name, 'Checkpoint', '') 
			if tonumber(checkpointNumber) == checkpointStat.Value + 1 then
				print("Stage update called")
				checkpointStat.Value = tonumber(checkpointNumber)
				
				--Checkpoint sound
				local ding = script.Ding:Clone()
				ding.Parent = child
				ding:Play()
				game.Debris:AddItem(ding, ding.TimeLength)
				
				--Checkpoint particle
				local newAttachment = Instance.new("Attachment")
				newAttachment.Name = "ParticleAttachment"
				newAttachment.Parent = child
				local newParticle = script.Particle:Clone()
				newParticle.Parent = newAttachment
				newParticle.Changed:connect(function()
					wait(0.15)
					newParticle.Enabled = false
					game.Debris:AddItem(newParticle, 0.75)
				end)
				newParticle.Enabled = true
				
				--Checkpoint animation
				local TweenService = game:GetService("TweenService")
				local Info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true, 0)
				local Goals = {
					Color = Color3.fromRGB(248, 248, 248);
					Reflectance = -2;	
					Orientation = Vector3.new(child.Orientation.X, child.Orientation.Y + 360, child.Orientation.Z);
					Position = Vector3.new(child.Position.X, child.Position.Y-0.95, child.Position.Z)
				}
				local tween = TweenService:Create(child, Info, Goals)
				tween:Play()
			end
		elseif humanoid.Health > 99 then
			
			checkpointStat.Value = 1
			deathStat.Value = -1
			
			humanoid.Health = 0
				
			--Reset sound
			local fart = script.Reset:Clone()
			fart.Parent = hit.Parent:FindFirstChild("Torso")
			fart:Play()
			game.Debris:AddItem(fart, fart.TimeLength)
				
			--Reset animation
			local TweenService = game:GetService("TweenService")
			local Info = TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out, 0, true, 0)
			local Goals = {
				Reflectance = -2;
				Size = Vector3.new(child.Size.X + 10, child.Size.Y, child.Size.Z + 10);
			}
			local tween = TweenService:Create(child, Info, Goals)
			tween:Play()
				
			wait(1)
		
		end
	end)
end

end


You need to add a de-bounce, preferably before you check if the child’s name is “Reset”.

But I want it to be able to do tweens at once. I just want it to return to its original position once the second tween is done. Is there a way I could stop the tween from the first one and make the checkpoint return to its original position and then start the second tween?

Because what happening now is 0 → 2, but before it gets to 2 and comes back a player touches the checkpoint when its only halfway done with the first one. So the first goes from 1 → 3 and the checkpoint is lost into the ground lol.

Hello,

Try considering this. If your part keeps falling to the ground because of so many players at once. Perhaps you need to use these variables.

local childPosition = child.Position
local childOrientation = child.Orientation

Put those variables above the Touched event so it doesn’t get current value while being animated.

Then, during the time where it is tweened, try this.

Position = Vector3.new(childPosition.X, childPosition.Y-0.95, childPosition.Z)
Orientation = Vector3.new(childOrientation.X, childOrientation.Y + 360, childOrientation.Z)

These values will be customized inside your checkpoint tween. Any more problems?

1 Like

I will test this with multiplayer rq see if it works. Seems like it should

Wait so where should I define these variables because this script manages all the checkpoints. If I have it when it’s touched how will I know if that is the original position?

for i, child in ipairs (script.Parent:GetChildren())do
   if child.ClassName == ‘Part’ then
      --PUT THESE VARIABLES IN HERE.
      local childPosition = child.Position
      local childOrientation = child.Orientation
      --
      child.Touched:connect(function(hit)
      –Check for Player
      local player = game.Players:GetPlayerFromCharacter(hit.Parent)
      if not player then return end
          –Check for Player’s humanoid and that its alive
          local humanoid = hit.Parent:FindFirstChild(“Humanoid”)
          if not humanoid or humanoid.Health <= 0 then return end

I edited the first part of your script code to show you the appropriate places.

This may seem useless. But they will get the very first Vector3 values that the part’s orientation or the position has originated with before change.

1 Like

Ah I understand it now. It appears to work. Thankyou!

1 Like