Trying to prevent animation spam

I have an automatic gun system, but I’m running into the issues on client with animation spam, that if you spam click then animations will be spammed. Like it plays new animation before old one ends. I really don’t know how to explain it, so here’s a video of what i mean by “spam”:

Local script:

local firing = false

function shoot()
	if not firing then
		if ammo > 0 then
			firing = true
			repeat
				local camera = workspace.CurrentCamera
				camera.CFrame:Lerp(camera.CFrame * CFrame.Angles(1, 0, 0), 0.3)
				event:FireServer(camera.CFrame.Position, camera.CFrame.LookVector)
				
				task.spawn(function()
					fx1.Enabled = true
					fx2.Enabled = true
					task.wait(0.09)
					fx1.Enabled = false
					task.wait(0.5)
					fx2.Enabled = false
				end)
				
				shootAnim:Play()
				task.wait(0.2)
			until not firing
		end
	else
		firing = false
	end
end

tool.Equipped:Connect(function()
	starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	
	cas:BindAction("Shoot", shoot, true, Enum.UserInputType.MouseButton1)
	cas:SetTitle("Shoot", "Shoot")
	cas:SetPosition("Shoot", UDim2.new(0.15, 0, 0.2, 0))
end)

How can I make a cooldown for this or something like that? Thanks in advance.

Hi,

I’m assuming you want to wait for the duration of the animation to end, so then the player is unable to shoot until the animation ends.

I would recommend looking into KeyframeSequenceProvider to learn more about the duration and such of animations.

You can also see an example of it being used here: How to make your first Combat System R15 and R6 | Part 1 - YouTube

(At 15:20)

I would just create a variable or do something like that to wait until the animation has fully played.

1 Like

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