So im animating my viewmodel for a gun but the shooting animation just doesnt want to work at all.
There is nothing in the output and no signs of any wrong things in the code.
The code is a serverscript bc i have a function that does something when firing the gun there.
Heres the code that i use (only the parts that actually matter on this topic)
local replicatedStorage = game.ReplicatedStorage
local VModel = replicatedStorage:WaitForChild("ViewModel")
local VModelHumanoid = VModel:WaitForChild("Humanoid")
-- Ensure the Humanoid has an Animator
local animator = VModelHumanoid:FindFirstChild("Animator")
if not animator then
animator = Instance.new("Animator")
animator.Parent = VModelHumanoid
end
local RecoilAnim = Instance.new("Animation")
RecoilAnim.AnimationId = "rbxassetid://73833512534529"
-- Function to play the fire sound and animation
function PlayFireSound()
local NewSound = FireSound:Clone()
local MuzzleFlash = script.Parent.Handle.MuzzleFlash.MuzzleEffect
NewSound.Parent = Handle
NewSound:Play()
MuzzleFlash:Emit(20)
-- Load and play the animation
local animationTrack = animator:LoadAnimation(RecoilAnim)
animationTrack:Play()
-- Clean up the sound after it finishes playing
Debris:AddItem(NewSound, NewSound.TimeLength)
end
I have no idea whats the issue and why doesnt it work. If u know whats wrong pls reply to this topic with the answer. Thanks for helping