So I made some animations for some guns
but for whatever reason when i swap the animations and guns out this happens:
Code used:
local function Equip(Name)
Weapon = game.ReplicatedStorage.Weapons[Name]
--Stat change here
Weapon = CLM.Equip(Viewmodel, Weapon)
end
function CLM.Equip(Viewmodel, Gun)
for _,Anim in pairs(Viewmodel.AnimationController:GetPlayingAnimationTracks()) do
Anim:Stop(0)
end
if GunModel then GunModel:Destroy() end
GunModel = Gun:Clone()
local GunHandle = GunModel.Handle
local RootMotor = Viewmodel:WaitForChild("Right Arm"):WaitForChild("Right Arm").Handle
if Gun.GunAnimations:FindFirstChild("Hold") then
local HoldAnim = Gun.GunAnimations.Hold
CurrentAnims.Hold = Viewmodel.AnimationController:LoadAnimation(HoldAnim)
local EquipAnim = GunModel.GunAnimations.Equip
CurrentAnims.Equip = Viewmodel.AnimationController:LoadAnimation(EquipAnim)
CurrentAnims.Hold:Play(0)
CurrentAnims.Equip:Play(0,1,GunModel.GunStats.AnimationSpeed.Value)
end
GunModel.Parent = Viewmodel
RootMotor.Part1 = GunHandle
return GunModel
end
-- Pre welds the guns for animations
function Module.Weld(Gun)
local Main = Gun.Handle
for i,v in ipairs(Gun:GetDescendants()) do
if v:IsA("BasePart") and v ~= Main then
local NewMotor = Instance.new("Motor6D")
NewMotor.Name = v.Name
NewMotor.Part0 = Main
NewMotor.Part1 = v
NewMotor.C0 = NewMotor.Part0.CFrame:Inverse() * NewMotor.Part1.CFrame
NewMotor.Parent = Main
end
end
end
for _,Weapon in pairs(game.ReplicatedStorage.Weapons:GetChildren()) do
Module.Weld(Weapon)
end
Explorer:
Replicated Storage:
Viewmodel:
Any help would be appreciated