My animation "Debounce" will not work on the client side

I want to make a reloading animation for my gun.

My Debounce wont work and I do not know how to make it work on the server with my script

DevForum

I am using the Client (LocalScript) and I am trying to make it so that they can’t spam reload and so that when the weapon is equipped they can reload. But when the weapon isn’t equipped it will still play it if I click "R" on my keyboard. This is used with UserInputService. The LocalScript is inside of the tool not the player and I do not understand how to make it Debounce from the Server (Script)

game:GetService("UserInputService").InputBegan:Connect(function(key,gameP)
	local result = ""
	if key.KeyCode == Enum.KeyCode.R or key.KeyCode == Enum.KeyCode.ButtonX and result == "" and held == true and not gameP then
		result = "Playing"
		idleAnim:Stop()
		wait()
		shootAnim:Stop()
		wait()
		reloadAnim:Play()
		wait()
		reloadAnim.Stopped:Wait()
		idleAnim:Play()
		wait(0.5)
		result = ""
	elseif result ~= "" and held ~= true then
		return nil
	end
end)

try this

script.Parent.Equipped:Connect(function() --when tool equipped
	game:GetService("UserInputService").InputBegan:Connect(function(key,gameP)
		local result = ""
		if not gameP then
			if key.KeyCode == Enum.KeyCode.R or key.KeyCode == Enum.KeyCode.ButtonX and result == "" then
				result = "Playing"
				idleAnim:Stop()
				shootAnim:Stop()
				reloadAnim:Play()
				reloadAnim.Stopped:Wait()
				idleAnim:Play()
				wait(0.5)
				result = ""
			elseif result ~= "" and held ~= true then
				return nil
			end
		end
	end)
end)

1 Like

When the tool unequips will the code not work? until equipped again I also can’t test rn but I will later

So @RealingZeeKung it works but I can still spam it when it gets equipped and when I unequip it, I can still use the animation (after equipping then unequipping)