Help canceling CFrames reload animation

I want to stop the CFrame animation when the player is running, actually i’m using ACS 2.0.0 (R15) for testing purpose. The reload script is a model script that contains all the animations of the gun, so i can’t cancel one of them because there are waits that stops are the code. I try to make a loop and check if the player is running, but if the player runs in the middle of the reload and stop running fast the reload continues. So i don’t what i can do.

Module animation script:

self.ReloadAnim = function(Model)
	local ReloadTable = {
		TweenService:Create(Model[1], TweenInfo.new(.25,Enum.EasingStyle.Sine), {C1 = (CFrame.new(0.05,-0.15,.85) * CFrame.Angles(math.rad(110),math.rad(-15),math.rad(0))):inverse() }),
		TweenService:Create(Model[2], TweenInfo.new(.25,Enum.EasingStyle.Sine), {C1 = (CFrame.new(-.65,0,.2) * CFrame.Angles(math.rad(110),math.rad(-15),math.rad(30))):inverse() }),

		TweenService:Create(Model[1], TweenInfo.new(.5,Enum.EasingStyle.Back), {C1 = (CFrame.new(0.05,-0.15,.85) * CFrame.Angles(math.rad(100),math.rad(-5),math.rad(0))):inverse() }),
		TweenService:Create(Model[2], TweenInfo.new(.25,Enum.EasingStyle.Back), {C1 = (CFrame.new(-.75,-0.15,1) * CFrame.Angles(math.rad(60),math.rad(-5),math.rad(15))):inverse() }),

		TweenService:Create(Model[2], TweenInfo.new(.25,Enum.EasingStyle.Sine), {C1 = (CFrame.new(-.65,0,.2) * CFrame.Angles(math.rad(110),math.rad(-15),math.rad(30))):inverse() }),
		TweenService:Create(Model[1], TweenInfo.new(.15,Enum.EasingStyle.Sine), {C1 = (CFrame.new(0.05,-0.15,.85) * CFrame.Angles(math.rad(101),math.rad(-6),math.rad(0))):inverse() })	
	}
	
	ReloadTable[1]:Play()
	ReloadTable[2]:Play()

	wait(.25)
		
	ReloadTable[3]:Play()
	ReloadTable[4]:Play()

	wait(.05)
		
	Model[4].Handle.MagOut:Play()	
	Model[4].Mag.Transparency = 1

	wait(.5)
		
	Model[4].Handle.AimUp:Play()
		
	wait(.75)
		
	ReloadTable[5]:Play()

	wait(.25)
		
	Model[4].Handle.MagIn:Play()
		
	ReloadTable[6]:Play()
	
	Model[4].Mag.Transparency = 0
end

--> Idle anim
self.IdleAnim = function(objs)
	TweenService:Create(objs[1], TweenInfo.new(self.DrawWeapon, Enum.EasingStyle.Sine), {C1 = self.RArmCFrame:Inverse()}):Play()
	TweenService:Create(objs[2], TweenInfo.new(self.DrawWeapon, Enum.EasingStyle.Sine), {C1 = self.LArmCFrame:Inverse()}):Play()
end

1 Like

well you gotta cancel the tween for it to stop, it wont just stop on its own

you either have tween:Cancel() or tween:Pause()

cancel will stop the tween and next time you play it will restart from the beginning

pause will stop it and save its time position for the next time you play it

Thank you for the answer but i have tried that before and what happens is that task.wait() delays the tween so it doesn’t cancel it.

Code i have written.

self.ReloadAnimation = false

self.ReloadAnim = function(Model)
	
	self.ReloadAnimation = true
	
	local ReloadTable = {
		TweenService:Create(Model[1], TweenInfo.new(.25, Enum.EasingStyle.Sine), {C1 = (CFrame.new(0.05,-0.15,.85) * CFrame.Angles(math.rad(110),math.rad(-15),math.rad(0))):inverse() }),
		TweenService:Create(Model[2], TweenInfo.new(.25, Enum.EasingStyle.Sine), {C1 = (CFrame.new(-.65,0,.2) * CFrame.Angles(math.rad(110),math.rad(-15),math.rad(30))):inverse() }),

		TweenService:Create(Model[1], TweenInfo.new(.5, Enum.EasingStyle.Back), {C1 = (CFrame.new(0.05,-0.15,.85) * CFrame.Angles(math.rad(100),math.rad(-5),math.rad(0))):inverse() }),
		TweenService:Create(Model[2], TweenInfo.new(.25, Enum.EasingStyle.Back), {C1 = (CFrame.new(-.75,-0.15,1) * CFrame.Angles(math.rad(60),math.rad(-5),math.rad(15))):inverse() }),

		TweenService:Create(Model[2], TweenInfo.new(.25, Enum.EasingStyle.Sine), {C1 = (CFrame.new(-.65,0,.2) * CFrame.Angles(math.rad(110),math.rad(-15),math.rad(30))):inverse() }),
		TweenService:Create(Model[1], TweenInfo.new(.15, Enum.EasingStyle.Sine), {C1 = (CFrame.new(0.05,-0.15,.85) * CFrame.Angles(math.rad(101),math.rad(-6),math.rad(0))):inverse() })	
	}
	
	--> Tween animation
	
	spawn(function()
		
		ReloadTable[1]:Play()
		ReloadTable[2]:Play()

		task.wait(.3)

		ReloadTable[3]:Play()
		ReloadTable[4]:Play()

		task.wait(.05)

		Model[4].Handle.MagOut:Play()	
		Model[4].Mag.Transparency = 1

		task.wait(.5)

		Model[4].Handle.AimUp:Play()

		task.wait(.75)

		ReloadTable[5]:Play()

		task.wait(.25)

		Model[4].Handle.MagIn:Play()

		ReloadTable[6]:Play()

		Model[4].Mag.Transparency = 0

		self.ReloadAnimation = false
		
	end)
	
	--> Test code just to be if Tweens gets canceled.
	
	spawn(function()
		
		for Tween, v in pairs(ReloadTable) do
			ReloadTable[Tween]:Cancel()
		end
		
	end)

end

self.IdleAnim = function(Model)
	
	spawn(function()
		
		repeat task.wait() until not self.ReloadAnimation
		
		TweenService:Create(Model[1], TweenInfo.new(self.DrawWeapon, Enum.EasingStyle.Sine), {C1 = self.RArmCFrame:Inverse()}):Play()
		TweenService:Create(Model[2], TweenInfo.new(self.DrawWeapon, Enum.EasingStyle.Sine), {C1 = self.LArmCFrame:Inverse()}):Play()	
		
	end)
	
end

spawning a function will make them run at the same time not after each other so what happens here is

you spawn a new function and the script continues
it spawns an another function and continues

spawn’s functions get called shortly after and they run at the same time

probably because the cancel code is smaller it will run faster than the playing code making it cancel nothing then play the tween

I can’t quit the spawn function because i need it to not stop all the script, and as i said before the tween doesn’t play because there is a task.wait() so my only idea is to make a loop that checks if the player is running, but when i try to cancel the tween it doesn’t stop.

Here are some videos that i want to do:
Normal reload (without running): Normalreload - YouTube
Running reload (Here i want to stop the tweens and make the sprint animation): Sprintreload - YouTube

And the baseplate if you want to test it yourself.
ACS.rbxl (1.0 MB)

Thank you for your time :slight_smile:

Sort of difficult, I would recommend using a boolean object that can communicate from client script to module script, because the anim script is just a module script not associated with the main client script handling anims.

in the reload anim function you would need a property changed signal of this boolean object (of course disconnecting it once the script was reached the end), (assuming it isn’t true already before checking) have a localized boolean var for your reloadanim function so that once the boolean object triggers the condition to cancel reload anims and inevitably set the localized boolean to break value, after every wait, you would check if the condition to break is met, and return

NOTE i believe acs natively will not like this, whenever the anim func ends, it completes the reload functionality i.e. you will have fully reloaded the gun when the anim function returns/ends at any time

perhaps to cirvumvent this, have the function set to a local variable where the reload anim is called, check if the variable == true or false, in this case you will need the anim to return true at the end of the anim cycle, false in all others

1 Like

Thanks you seems to be working now, but i need to do a loop in the larger times because if not the sprint animation goes with delay (Also a small question, how much ‘for loops’ consume because there is like 2 in the animation and i don’t know if is going to have a heavily lag or something is low devices, it only checks is player is running and wait the animation time).

for i = 1, 75 do
	if IsPlayerRunning then
		break
	end
	task.wait(0.01)
end

About checking if the player is running to cancel the interpolation every time there is a task.wait() is there a better way to check it than putting an ‘if’ every time there is a task.wait() or is that the only way?

Thank you for your answer <3.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.