How To Fix Tween Bugging Out And Stopping Early

Here’s a video which shows exactly what I’m talking about:
https://gyazo.com/cf304fec72e669dcea817b80281a0cb6

Basically, while I was testing, I was checking to see if the tween would stop early and I realized that it happens when I touch the checkpoints quickly as can see in the video.

Is there any way to improve this code so that it completes the tween??

Full local script code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local arrow = ReplicatedStorage:WaitForChild("Arrow")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

arrow.OnClientEvent:Connect(function()
	local player = Players.LocalPlayer
	local cloneStar = workspace:FindFirstChild("Star")
	print("Connected")
	
	
	local level = player:WaitForChild("leaderstats").Level
	print("Leaderstats found")


	if cloneStar ~= nil then
		local leveldata = level.Value
		if game.Workspace.Checkpoints:FindFirstChild(leveldata + 1) then			
			local sl = game.Workspace.Checkpoints:FindFirstChild(leveldata + 1)
	
			
			cloneStar:SetPrimaryPartCFrame(CFrame.new(sl.Position + Vector3.new(0,13.5,0)))
			
			
			local PrimaryPart = cloneStar.PrimaryPart
			
			
			local tweenInfo2 = TweenInfo.new(1.75,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,true,0 )	
		
			
			local FloatPosition = { Position = PrimaryPart.Position + Vector3.new(0,4.5,0)}
			
			
			local tween2 = TweenService:Create(PrimaryPart, tweenInfo2, FloatPosition)
			tween2:Play()
			print("Tween2 Activated")
		
			
			
			level.Changed:Connect(function(newval)
				print("on")
				if tween2 then		
					tween2:Cancel()	
					print("Cancelled")	
				end
				
				
				if cloneStar ~= nil then
					if game.Workspace.Checkpoints:FindFirstChild(newval + 1) then
						local ls = game.Workspace.Checkpoints:FindFirstChild(newval + 1)
						
					
						if PrimaryPart then			
							local tweenInfo = TweenInfo.new(0.9,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
							
							
							local NewPosition = {Position = ls.Position + Vector3.new(0,13.5,0)}
				
				
							local tween = TweenService:Create(PrimaryPart, tweenInfo, NewPosition)		
							
							
							tween:Play()
							print("Level changed to"..newval)
					
				
							tween.Completed:Wait()	
							print("Tween Completed")
				
										
							wait(0.9)
							
							local tweenInfo2nd = TweenInfo.new(1.75,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,true,0 )	


							local FloatPosition2 = { Position = PrimaryPart.Position + Vector3.new(0,4.5,0)}


							local tween2 = TweenService:Create(PrimaryPart, tweenInfo2nd, FloatPosition2)
							
				
							tween2:Play()
							print("Tween playing")
						end
						
				
					end

					
				end
				
				
			end)
			
			
		end
		
		
	end
	
	
end)

Anyone figured out anything that could help me??

If they did they would have replied.

1 Like