How do I stop this tween

I am adding realistic acceleration to my game so that players move a little slow before they get to their full speed. So when a player starts moving it starts a tween to change their walkspeed from 0 to 16. The issue I am having is if a player moves foward for one second the tween keeps playing so when that player moves again their walkspeed is already at 16 instead of stopping.

local accelerating = false

player.Character.Humanoid.Running:Connect(function(speed)
	
	local TweenService = game:GetService("TweenService")
	local humanoid = player.Character.Humanoid
	local Tween = TweenService:Create(humanoid, TweenInfo.new(5),{WalkSpeed = 16})
	
	if speed > 0 then
		if accelerating == false and player.Character.Humanoid.WalkSpeed ~= 0 then
			player.Character.Humanoid.WalkSpeed = 0
			accelerating = true
			
			Tween:Play()
			wait(5)
			accelerating = false
			print("Finished tween")
		end
		
	else
		print("Player has stopped")
		Tween:Cancel()
		player.Character.Humanoid.WalkSpeed = 0
	end
end)

So how can I cancel this tween so it doesn’t keep increasing the player’s walkspeed.

1 Like

you have to use :Stop() and not Tween:Cancel()

Stop() is not a valid member of tween I can only use Cancel() or Pause()

1 Like