I have tried to animate my viewmodel and my weapon in my FPS game, but it doesnt work. I’ve tried to rearange the parts and animator and everything, but it didnt change. The weird part is i can animate my Viewmodel prefectly fine but as soon as i try to animate my weapon it just doesn’t work.
Here is the current arrengment:
the “Groza” is the weapon
And this is how it looks ingame:
the script of the animation:
local module = {}
local function GetBobbing(addition,add1)
return math.sin(tick() * addition * 0.5) * add1
end
function module.update(viewmodel, dt, Recoilspring,SwaySpring, gun,BobSpring,isStanding,isSprinting,isScoping,ismenu)
if not ismenu.Value then
viewmodel.HumanoidRootPart.CFrame = game.Workspace.Camera.CFrame
local MouseDelta = game:GetService("UserInputService"):GetMouseDelta()
local Bobble = Vector3.new(0,GetBobbing(9,0.1),0)
local BobbleWalk = Vector3.new(0,GetBobbing(20,0.2),0)
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
if not isScoping then
if Character then
if Character.HumanoidRootPart.Velocity.Magnitude < 50 then
BobSpring:shove(BobbleWalk / 10 * (Character.HumanoidRootPart.Velocity.Magnitude) / 10)
if isStanding then
BobSpring:shove(Bobble / 10 * 0.5)
end
elseif Character.Humanoid.FloorMaterial == Enum.Material.Air then
BobSpring:shove(Vector3.new(0,(Character.HumanoidRootPart.Velocity.Magnitude) / 1000,0))
end
end
SwaySpring:shove(Vector3.new(-MouseDelta.X / 400, MouseDelta.Y / 150, 0))
else
SwaySpring:shove(Vector3.new(-MouseDelta.X / 650, MouseDelta.Y / 400, 0))
end
local UpdateRecoilSpring = Recoilspring:update(dt)
local UpdatedSwaySpring = SwaySpring:update(dt)
local UpdatedBobspring = BobSpring:update(dt)
gun.GunComponents.Sight.CFrame = gun.GunComponents.Sight.CFrame:Lerp(viewmodel.HumanoidRootPart.CFrame, game.ReplicatedStorage.values.AimAlpha.Value)
viewmodel.HumanoidRootPart.CFrame *= CFrame.new(UpdatedSwaySpring.X, UpdatedSwaySpring.Y, 0)
viewmodel.HumanoidRootPart.CFrame *= CFrame.Angles(math.rad(UpdateRecoilSpring.X) * 2,0,0)
viewmodel.HumanoidRootPart.CFrame = viewmodel.HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(UpdatedBobspring.X, UpdatedBobspring.Y,0))
game.Workspace.Camera.CFrame *= CFrame.Angles(math.rad(UpdateRecoilSpring.X),math.rad(UpdateRecoilSpring.Y),math.rad(UpdateRecoilSpring.Z))
game.Workspace.Camera.FieldOfView = game.ReplicatedStorage.values.SprintAlpha.Value
end
end
function module.weldgun(gun)
local Main = gun.GunComponents.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
function module.equip(viewmodel, gun, hold)
local Gunhandle = gun.GunComponents.Handle
local HRP_Motor6D = viewmodel:WaitForChild("HumanoidRootPart").Handle
gun.Parent = viewmodel
HRP_Motor6D.Part1 = Gunhandle
local Hold = viewmodel.Humanoid.Animator:LoadAnimation(hold)
Hold:Play()
end
function module.cast(origin, endpos, velocity, event,plyr)
local Bullet = Instance.new("Part")
Bullet.Size = Vector3.new(0.1,0.1,2)
Bullet.Name = "Bullet"
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Color = Color3.new(0.678431, 0.431373, 0)
Bullet.Material = Enum.Material.Neon
Bullet.Parent = game.Workspace
Bullet.CFrame = CFrame.new(origin, endpos)
local Loop
Loop = game:GetService("RunService").RenderStepped:Connect(function(dt)
Bullet.CFrame *= CFrame.new(0,0, -velocity * (dt * 60))
if (Bullet.Position - origin).magnitude > 5000 then
Bullet:Destroy()
Loop:Disconnect()
end
end)
local Hit = workspace:Raycast(Bullet.Position, Bullet.CFrame.LookVector * velocity * 10000)
if Hit then
if Hit.Instance.Parent:FindFirstChild("Humanoid") and event ~= nil then
event:FireServer(Hit.Instance.Parent, 10,plyr)
print("HIT")
else
Loop:Disconnect()
Bullet:Destroy()
end
end
end
function module.aim(toaim, viewmodel, gun)
local Aimalpha = game.ReplicatedStorage.values:WaitForChild("SprintAlpha")
if toaim then
game:GetService("TweenService"):Create(game.ReplicatedStorage.values.AimAlpha, TweenInfo.new(0.3), { Value = 1 }):Play()
game:GetService("TweenService"):Create(game.ReplicatedStorage.values.SprintAlpha, TweenInfo.new(0.2), {Value = 50}):Play()
else
game:GetService("TweenService"):Create(game.ReplicatedStorage.values.AimAlpha, TweenInfo.new(0.5), { Value = 0 }):Play()
game:GetService("TweenService"):Create(game.ReplicatedStorage.values.SprintAlpha, TweenInfo.new(0.2), {Value = 70}):Play()
end
end
function module.GetMouse(Distance, CastParams)
local MouseLocation = game:GetService("UserInputService"):GetMouseLocation()
local UnitRay = game:GetService("Workspace").Camera:ViewportPointToRay(workspace.CurrentCamera.ViewportSize.X / 2, workspace.CurrentCamera.ViewportSize.Y / 2)
local origin = UnitRay.Origin
local endp = UnitRay.Direction * Distance
local Hit = game:GetService("Workspace"):Raycast(origin, endp, CastParams)
if Hit then
return Hit.Position
else
return UnitRay.Origin + UnitRay.Direction * Distance
end
end
function module.Sprint(player, speed,isSprinting)
if player and player.Character then
if player.Character:FindFirstChildWhichIsA("Humanoid") then
player.Character:FindFirstChildWhichIsA("Humanoid").WalkSpeed = speed
end
end
if isSprinting then
game:GetService("TweenService"):Create(game.ReplicatedStorage.values.SprintAlpha,TweenInfo.new(0.1),{Value = 85}):Play()
else
game:GetService("TweenService"):Create(game.ReplicatedStorage.values.SprintAlpha,TweenInfo.new(0.1),{Value = 70}):Play()
end
end
function module.reload(viemodel,textlabel,ammo)
if ammo < 30 then
ammo = 30
return ammo
end
end
function module.setCustomViewmodel(character,viewmodel,players)
local Clothing = character:WaitForChild("Shirt").ShirtTemplate
local HumanoidDes = players:GetHumanoidDescriptionFromUserId(players.LocalPlayer.UserId)
local SkincolorR = HumanoidDes.RightArmColor
local SkincolorL = HumanoidDes.LeftArmColor
print(SkincolorR)
viewmodel.Clothing.ShirtTemplate = Clothing
viewmodel:FindFirstChild("Right Arm").Color= SkincolorR
viewmodel:FindFirstChild("Left Arm").Color = SkincolorL
end
return module
any help would be appriciated ![]()


