So I am working on an fps game currently and I am creating this viewmodel when you spawn in. Everything works perfectly except for the animation when you equip the gun.

I will try my best to describe the situation. When you equip the gun from the inventory, it plays an equipping animation. The problem is that the first time you equip the gun when you first load in, the animation doesn't play at all. The second time you equip the gun, it first appears in the hand already and plays the idle animation about half a second before it plays the reload animation so it looks clunky and weird. The weirdest part is sometimes it will play the equip animation first and it works smoothly but sometimes it doesn't. And on the first time you equip it it just doesn't do anything and goes straight to the idle animation.

Here is the excerpt of my script that is the cause of the problem. I have tried many things like commenting and re ordering but nothing seems to work. This is a local script and this is it's location: game-StarterPack-Handcannon-LocalScript

Keep in mind the first 7 lines don't have an effect (at least I don't think so) to my problem. I just included it because it was part of the same function.

local function equip()
	if not gun and ViewModel then return end
	for _, part in pairs(gun:GetChildren()) do
		if part:IsA('BasePart') or part:IsA('UnionOperation') then
			part.Transparency = 1
		end
	end
	ViewModel.Parent = Camera
	Humanoid.WalkSpeed = 0
	Animations.HandcannonEquip:Play()
	Animations.HandcannonEquip.Stopped:Wait()
	Humanoid.WalkSpeed = 16
	Animations.HandcannonIdle:Play()
	equipConnection = RunService.RenderStepped:Connect(function()
		positionModel()
	end)
end

7 comments

0

use a task.wait and if that dosnt work make the animation a instance and make a wait for child on the animation then it should wait for the animation to load

0

What is task.wait and where should I put it?

0

task.wait() is equivalent to renderstepped

0

the problem might be due to the rigging of the model

0

how so?

0

Could you send a video of the issue

0

It doesn't let me send videos