Animation not playing

Hello so I have made many animations in the past but this gun animation is not playing. There are no errors, I have tried debugging by putting “Print(‘bla’)” between the necessary lines. Here is my code and explorer. Everything is connected by welds and joints. Welds for stationary parts, joints for moving parts. Not the whole script is in the code below.

image

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local camera = game.Workspace.CurrentCamera

local aimCF = CFrame.new()

local isAiming = false

local fireAnim = nil
local fireSound = nil

local framework = {
	inventory = {
		"SPC-A3";
		"CZ-75";
	};
	
	module = nil;
	viewmodel = nil;
	currentSlot = 1;
}

function loadSlot(Item)
	local viewmodelFolder = game.ReplicatedStorage.ViewModels
	local moduleFolder = game.ReplicatedStorage.Modules
	
	for i,v in pairs(camera:GetChildren()) do
		if v:IsA("Model") then
			v:Destroy()
		end
	end
	
	if moduleFolder:FindFirstChild(Item) then
		framework.module = require(moduleFolder:FindFirstChild(Item))
		
		if viewmodelFolder:FindFirstChild(Item) then
			framework.viewmodel = viewmodelFolder:FindFirstChild(Item):Clone()
			framework.viewmodel.Parent = camera
			
			fireAnim = Instance.new("Animation")
			fireAnim.Parent = framework.viewmodel
			fireAnim.Name = "Fire"
			fireAnim.AnimationId = framework.module.fireAnim
			fireAnim = framework.viewmodel.AnimationController.Animator:LoadAnimation(fireAnim)
		end
	end
end

loadSlot(framework.inventory[1])

UserInputService.InputBegan:Connect(function(input)
	
	--// SWITCH WEAPONS \\--
	
	if input.KeyCode == Enum.KeyCode.One then
		if framework.currentSlot ~= 1 then
			loadSlot(framework.inventory[1])
			framework.currentSlot = 1
		end
	end
	
	if input.KeyCode == Enum.KeyCode.Two then
		if framework.currentSlot ~= 2 then
			loadSlot(framework.inventory[2])
			framework.currentSlot = 2
		end
	end
	
	--// AIM DOWN SIGHTS \\--
	
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		
		isAiming = true
	end
	
	--// SHOOTING \\--
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		fireAnim:Play()
		character.UpperTorso.Fire:Play()
	end
end)
2 Likes

Forgot the input ended in the code.

UserInputService.InputEnded:Connect(function(input)
	--// AIM DOWN SIGHTS \\--
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		isAiming = false
	end
	--// SHOOTING \\--
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
	end
end)
1 Like

i am pretty sure that instead of this:

fireAnim = framework.viewmodel.AnimationController.Animator:LoadAnimation(fireAnim)

you have to do this:

fireAnim = framework.viewmodel.AnimationController:LoadAnimation(fireAnim)

just load the animation into the controller

2 Likes

Just tried it, still isn’t moving at all.

2 Likes

hvae you tried adding print statemnts to see where the code is running>?

add on to the if statement jsut before the animation, and the statemen before that and so on. event inside event to see if they are being read

1 Like

yes I have tried that, appears to work fine but doesn’t move. Heres my settings module incase it helps:

local Settings = {
	
	canAim = true;
	aimSmooth = 0.08;
	
	fireAnim = "rbxassetid://120149200186043";
	fireSound = game.ReplicatedStorage.GunSounds["SPC-A3"].SoundId;
	
	canSemi = true;
	canAuto = true;
	
	fireMode = "Auto";
	
}

return Settings
1 Like

wait so you you did it liek this?

function loadSlot(Item)
	local viewmodelFolder = game.ReplicatedStorage.ViewModels
	local moduleFolder = game.ReplicatedStorage.Modules

	for i,v in pairs(camera:GetChildren()) do
		if v:IsA("Model") then
			v:Destroy()
		end
	end
	
	print('1')
	if moduleFolder:FindFirstChild(Item) then
		print("2")
		framework.module = require(moduleFolder:FindFirstChild(Item))
	
		if viewmodelFolder:FindFirstChild(Item) then
			print("3")
			framework.viewmodel = viewmodelFolder:FindFirstChild(Item):Clone()
			framework.viewmodel.Parent = camera

			fireAnim = Instance.new("Animation")
			fireAnim.Parent = framework.viewmodel
			fireAnim.Name = "Fire"
			fireAnim.AnimationId = framework.module.fireAnim
			fireAnim = framework.viewmodel.AnimationController.Animator:LoadAnimation(fireAnim)
		end
	end
end

and all the prints out putted?

1 Like

Yes, also did it where it plays it in the input began event.

1 Like

maybe its a problem with your rig? if you take the gun inside dstudio and open the animatiuon editor, then load the aniamtion like this
image
does it play normally? i mean the “from roblox” not “from fbx” sorry!

1 Like

Okay one moment, it appears to have removed the recoil (but kept the bolt movement which I can’t see as the player) so I will attempt to add it back.

2 Likes

make sure to load the animation using the gun animation controller
if you are trying to use another gun animation on this gun it may not work because of the joints name
make sure that the joints are active
note :- joints will not be active if any of the connected parts are anchored*

1 Like

alright but can you also chaneg the part were you dont directly load the aniamtion to the controller? it still seems liek the main issue, even in the roblox documentation it doesnt say to do that

1 Like

Okay I’ll send a video in just a moment aswell.

2 Likes

1 Like

So basically everything works but the animation.

1 Like

so its not playing the animation at all it seems correct? did you change this line yet?

also if that dopesnt work maybe try change your settings module to this:

local Settings = {

	canAim = true;
	aimSmooth = 0.08;

	fireAnim = nil;
	fireSound = game.ReplicatedStorage.GunSounds["SPC-A3"].SoundId;

	canSemi = true;
	canAuto = true;

	fireMode = "Auto";

}

Settings.fireAnim = Instance.new("Animation")
Settings.fireAnim.Name = "Fire"
Settings.fireAnim.AnimationId = "rbxassetid://120149200186043"

return Settings

and then chaneg this:

			fireAnim = Instance.new("Animation")
			fireAnim.Parent = framework.viewmodel
			fireAnim.Name = "Fire"
			fireAnim.AnimationId = framework.module.fireAnim
			fireAnim = framework.viewmodel.AnimationController.Animator:LoadAnimation(fireAnim)

to this:

fireAnim = framework.viewmodel.AnimationController.Animator:LoadAnimation(framework.module.fireAnim)

you do not need to set the animation instance a parent btw

1 Like

Still isn’t working. Tried both of those.

1 Like

alright soooo, do you mind if i get access to your game to try and fix it myself? :grin: i just cant think of anything else and i would like to do my own debugging! only if you are confortable with it ofcourse

Sure I’ll send you a copy of the game in messages (I don’t know if dev forum has them if not then I’ll send here…

alright so it works just fine, the problem is the animation doesnt even move the gun. make a new one and animate the gun. i created my own for testing and it works. mycomputor isnt good so i cant screen record but yeah. can you try remakign the animation but adding movement to “main”

image

click add all body

image

and then select “Main”

publish the aniamtion add chaneg the id to the new one. let me know if it works

1 Like