How to stop my animation from bugging

I want to make my gun have animation on idle, shoot and reload.

Whenever I click the animation for idle plays and when I equip the gun and shoot it will still play the idle even though I stopped it.

Devforum and YouTube

This is all happening on the client and not the server, I cannot make a video sadly it keeps corrupting :frowning: But I will say that the gun is not buggy it is that the animation will play on click when it isn’t meant to, I am using UserInputService for the shooting anim btw.

--// Client \\--
local WeaponTool = script.Parent
local Player = game.Players.LocalPlayer
held = false
mouseDown = false

repeat wait() until Player.Character

local char = Player.Character

idleAnim = char:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(script:WaitForChild("Idle"))
shootAnim = char:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(script:WaitForChild("Shoot"))
reloadAnim = char:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(script:WaitForChild("Reload"))

script.Parent.Equipped:Connect(function()
	held = true
	idleAnim:Play()
	game.ReplicatedStorage:WaitForChild("ConnectM6D"):FireServer(WeaponTool:WaitForChild("BodyAttach"))
	char:WaitForChild("UpperTorso"):WaitForChild("ToolGrip").Part0 = char:WaitForChild("UpperTorso")
	char:WaitForChild("UpperTorso"):WaitForChild("ToolGrip").Part1 = WeaponTool:WaitForChild("BodyAttach")
end)

game:GetService("UserInputService").InputBegan:Connect(function(key,gameP)
	if key.KeyCode == Enum.KeyCode.R or key.KeyCode == Enum.KeyCode.ButtonX and held == true and not gameP then
		idleAnim:Stop()
		shootAnim:Stop()
		reloadAnim:Play()
		reloadAnim.Stopped:Wait()
		idleAnim:Play()
		game.ReplicatedStorage:WaitForChild("ReloadGun"):FireServer()
	end
end)

game:GetService("UserInputService").InputBegan:Connect(function(key,gameP)
	mouseDown = true
	if key.UserInputType == Enum.UserInputType.MouseButton1 or key.KeyCode == Enum.KeyCode.ButtonR2 and held == true and not gameP then
		while mouseDown do
			if held == false then
				break
			end
			wait()
			shootAnim:Play()
			shootAnim.Stopped:Wait()
		end
	end
end)

game:GetService("UserInputService").InputEnded:Connect(function(key,gameP)
	if key.UserInputType == Enum.UserInputType.MouseButton1 or key.KeyCode == Enum.KeyCode.ButtonR2 and held == true and mouseDown == true and not gameP then
		mouseDown = false
		shootAnim:Stop()
		idleAnim:Play()
	end
end)

WeaponTool.Unequipped:Connect(function()
	held = false
	mouseDown = false
	shootAnim:Stop()
	reloadAnim:Stop()
	idleAnim:Stop()
	game.ReplicatedStorage:WaitForChild("DisconnectM6D"):FireServer()
end)

--// Server \\--
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local M6D = Instance.new("Motor6D", char.UpperTorso)
		M6D.Name = "ToolGrip"
	end)
end)

game.ReplicatedStorage.ConnectM6D.OnServerEvent:Connect(function(plr,location)
	local char = plr.Character
	char.UpperTorso.ToolGrip.Part0 = char.UpperTorso
	char.UpperTorso.ToolGrip.Part1 = location
end)

game.ReplicatedStorage.DisconnectM6D.OnServerEvent:Connect(function(plr)
	plr.Character.UpperTorso.ToolGrip.Part1 = nil
end)

Also this happens when I use UserInputService it does it, :frowning:

1 Like

Also this is for R15!! Not R6 :grinning_face_with_smiling_eyes:

1 Like