Tool Animation not working

People, I am seriously losing my mind right now.

I am creating a lil practically still animation of the character holding the gun and it is literally not working, I have no idea why.

when I run .IsPlaying on the animation track, it returns True, however I do not see it.

What I have tried: This is a group game so I set the creation owner of as according the group. Before this, since it was still, I thought of using welds and CFrame rotations/orientations to move the left Arm so I can try and just have it next to the gun but I abandoned it half way, should I go back to it and if so, how should I tackle it.

Here is the LocalScript of the gun:

local userInputService = game:GetService(“UserInputService”)
local LaserRenderer = require(game.StarterPlayer.StarterPlayerScripts.LaserRenderer)
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local targetDamageEvent = game.ReplicatedStorage.Events.TargetRegistry
local partTargetDamageEvent = game.ReplicatedStorage.Events.TargetHitEvent
local laserRenderEvent = game.ReplicatedStorage.Events.LaserRendering
local targetFolder = workspace.TargeFolder

local player = game:GetService(“Players”).LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)

local tool = script.Parent
local muzzle = tool:WaitForChild(“Muzzle”)
local ammo = 30
local clipSize = ammo

local holdAnimation = Instance.new(“Animation”, tool)
holdAnimation.AnimationId = “rbxassetid://12802793658”
local animator = humanoid:FindFirstChildOfClass(“Animator”)
local animationTrack = animator:LoadAnimation(holdAnimation)

local pressed = userInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
local reload = false

local maxMouseRange = 1000
local maxRayRange = 999

local function getMouseLocation()
local mouseLocation = userInputService:GetMouseLocation()
local screenToWorldRay = workspace.CurrentCamera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y) – This part uses the x and y axis of the 2d mouse data in order to get a ray of where it is pointing at.
local directionVector = screenToWorldRay.Direction * maxMouseRange

local raycastResult = workspace:Raycast(screenToWorldRay.Origin, directionVector)

if raycastResult then
	return raycastResult.Position
else
	return screenToWorldRay.Origin + directionVector
end

end

local function equip()
– Positioning of the weapon to be held by 2 hands

--tool.Handle.Parent = character.LeftHand + character.RightHand


tool.Handle.Equip:Play() -- Equip SFX
animationTrack:Play()
print(animationTrack.IsPlaying)

end

local function reloadFunc()
reload = true
tool.Name = “[REL]”
tool.Handle.Reload:Play()
task.wait(4.5)
clipSize = 30
reload = false
tool.Name = “[”…clipSize…“]”
end

local function reloadAction(key, gameProcessedEvent)
if key.KeyCode == Enum.KeyCode.R and reload == false and clipSize < ammo then
reloadFunc()
end
end

local function activate()
if clipSize == 0 then
if reload == true then
else
reloadFunc()
end
else
pressed = userInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)

	while pressed and task.wait(0.13) and reload == false and clipSize > 0 do
		
		tool.Handle.Activate:Play()
		
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {player.Character}
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		local mousePointer = getMouseLocation()
		local targetDirectionVector = (mousePointer - muzzle.Position).Unit * maxRayRange
		
		local raycastResult = workspace:Raycast(muzzle.Position, targetDirectionVector, raycastParams)
		
		local raycastResultIndex = 0
		
		if raycastResult then
			local hitPosition = raycastResult.Position
			local contactModel = raycastResult.Instance.Parent
			
			
			raycastResultIndex += 1
			
			
			if contactModel then
				local humanoid = contactModel:FindFirstChild("Humanoid")
				
				if humanoid then
					targetDamageEvent:FireServer(humanoid)
					laserRenderEvent:FireServer(muzzle.Position, hitPosition)
					
				elseif contactModel == targetFolder then
					for _, target in targetFolder:GetChildren() do
						if raycastResult.Instance == target then
							partTargetDamageEvent:FireServer(target)
						else
						end
					end
				end
			else
				
				local hitPosition = muzzle.Position + targetDirectionVector
				laserRenderEvent:FireServer(muzzle.Position, hitPosition)
			end
		
			LaserRenderer.createLaser(muzzle.Position, hitPosition)
		else
			local hitPosition = muzzle.Position + targetDirectionVector
			laserRenderEvent:FireServer(muzzle.Position, hitPosition)
			LaserRenderer.createLaser(muzzle.Position, hitPosition)
		end
		
		pressed = userInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
		clipSize -= 1
		tool.Name = "["..clipSize.."]"
		
		if clipSize == 0 then
			reloadFunc()
		end
	end
end

end

local function unequipped()
pressed = false
animationTrack:Stop()
end

local function renderServerSideLasers(shootingPlayer, originPosition, endPosition)
if shootingPlayer ~= player then
LaserRenderer.createLaser(originPosition, endPosition)
end
end

tool.Equipped:Connect(equip)
userInputService.InputBegan:Connect(reloadAction)
tool.Activated:Connect(activate)
tool.Unequipped:Connect(unequipped)
laserRenderEvent.OnClientEvent:Connect(renderServerSideLasers)

Serverside and laser rendering all works fine and are not part of the problem, however they follow the system in the ROBLOX guide as it is noted to be the most efficient (other than the laser rendering which was purely for beginnner creation)

Prerequisite information: R6 model, All parts are welded to the Arm as it is like an RCL gun. All parts of the gun are held together with qPerfectionWeld script. I use ToolGrip editor from a guy who has goose in his name. P.S: Yes, the animation is already set on loop.

Basically what I am asking: how can I get the animation to work where the animation is a simple rotation of the other hand so it is holding the gun, either via CFrame rotation or animation, thank you and sorry if this was not a very clear topic, please give some replies for clarification or how I can improve this topic.

just like always is the animation working but not how you expected to work then its a animation aka grip problem don’t forget that it does not matter what you do roblox keeps assigning the default tool animation there are 2 ways to fix it set the grip right or remove the tool equip animation in the local script who is called animation in players character if the problem still exists ill see if the animation it self is working.

2nd if the animation not playing at all there may be some issues regards to script implantation OR the most issues these days is people forgetting to set those animations to loop and not just stop and go back to the default track if the problem still exists please reply with more issue details pics and videos will be better than white alphabets in the end your luck of hitting a engine bug is 1/low but not impossible :slight_smile: now i made you doubt if its you or engine issue Xd it cannot be script because we are on luau not python

Yes, the animation is indeed on loop, sorry forgot to include that

bro I am not gonna lie, I understood very little with the solution you have presented me

seems wierd stating that you are a programmer anyways like always i can’t help you just ba saying

I understood very little with the solution you have presented me

i expect atleast some information about the issues your are facing i can’t help you further with this awnser i asked also questions in my previous reply you didn’t awnser i wonder if you read it.

ight my bad, fair enough, solved it anyways

Welp, I am not sure what I did, but I did somehow fix it, here is at least the steps I did for anyone searching it up on google if they are in the same predicament.

  1. I completely scrapped the old animation, making a new one, however, instead of making it with a copy of the tool I was making the animation for, I was making the tool directly (used welds with the tool and welded it to the right hand as to make it easy to animate with as it had multiple parts, deleting those welds later when I put the tool back in StarterPack. (Since it was multiple parts, keeping the tools welded together, I used a third party script along the line called qPerfetionWeld, however, manually welding the objects its Handle wouldn’t have been hard if you have barely any parts to it anyways.)

  2. When making the animation, make sure to set it at loop, or you can do this on the later step when you incorporate the animation using the inbuilt property when you are scripting

  3. Publish the made animation, saving it to ROBLOX and click the link given as the result. NOTE: if you made the experience under a group, you also have to publish the animation as the creator of the group otherwise it won’t work - this was ROBLOX’s safety measure against asset copying

  4. When you get your animation, copy its ID and set it to the “rbxassetid://[ID HERE]” namely as to access it from ROBLOX’s resources.

  5. When scripting out the activation of your animation, here were the notable things that would have given effect to the animations, firstly, save it under a variable and then create a track of it. Even though it is deprecated I used the humanoid:LoadAnimation([ANIMATION VARIABLE]) method as it was quick and easy (refer to the Animator in documentation or the forum if you want to use more modern methods).

  6. There are 2 extremely important attributes you should consider to make sure the code works.

  • First, include the animationTrack and set its attribute of .Looped = true just in case.
  • Secondly, use the AnimationPriority attriubute set to Enum.AnimationPriority.Idle as this, in my case, was the simple idle animation/pose of the character with the gun. Refer to AnimationPriority here AnimationPriority | Roblox Creator Documentation.

P.S, play the track with :Play() only after the looped and animation priority has been set as to make the changes apparent

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