In my viewmodel, after a time the model start going “crazy”
function updateVM(viewmodel)
local Anim = getData(module, "Yes", camera:FindFirstChildWhichIsA("Model"))
local animation = Anim[4]
local IdleAnimation = viewmodel.Animation:LoadAnimation(animation)
IdleAnimation.Looped = true
IdleAnimation:Play()
viewmodel.Parent = camera
local humanoid = Character.Humanoid
local isRunning = false
humanoid.Running:Connect(function(speed)
isRunning = speed > 0
end)
GunConection = RunService.RenderStepped:Connect(function()
local targetCFrame = camera.CFrame
local currentCFrame = viewmodel:GetPrimaryPartCFrame()
local newCFrame
if not isRunning and not IsAnAnimationPlaying then
newCFrame = currentCFrame:Lerp(targetCFrame, 0.1)
else
newCFrame = targetCFrame
end
viewmodel:SetPrimaryPartCFrame(newCFrame)
local values = getData(module, "Yes", camera:FindFirstChildWhichIsA("Model"))
local folder = values[5]
local text = tostring(folder.ActualBullets.Value)
local text2 = tostring(folder.TotalBullets.Value)
HUD.Frame.BulletLabel.Text = text
HUD.Frame.BulletLabel2.Text = text2
end)
end
Others functions:
local function shootvm(AnimController)
local anims = getData(module, "Yes", camera:FindFirstChildWhichIsA("Model"))
while canShoot and anims and anims[5].ActualBullets.Value > 0 do
local ShootAnim = anims[1]
local anim = AnimController:LoadAnimation(ShootAnim)
local ShootFX = ShootAnim.Parent.Parent.BarrelParts.Particle.Shoot
local ValuesFolder = anims[5]
anim.Priority = Enum.AnimationPriority.Action
local ShootSound = AnimController.Parent.Sounds.ShootSound:Clone()
IsAnAnimationPlaying = true
anim:Play()
Frameworks.BulletFramework:GenerateRaycast(Player:GetMouse(), OnShoot)
ShootSound.Parent = AnimController.Parent.Handle
ShootSound:Play()
ShootFX:Emit(20)
ValuesFolder.ActualBullets.Value = ValuesFolder.ActualBullets.Value - 1
ShootSound.Ended:Connect(function()
ShootSound:Destroy()
isShotting = false
wait(0.1)
IsAnAnimationPlaying = false
end)
wait(0.125)
end
end
local function reloadvm(AnimController)
if canReload == true and not isReloading then
canReload = false
local models = getData(module, "Yes", camera:FindFirstChildWhichIsA("Model"))
local ReloadAnim = models[2]
local Values = models[5]
if Values.TotalBullets.Value then
isReloading = true
local anim = AnimController:LoadAnimation(ReloadAnim)
anim.Priority = Enum.AnimationPriority.Action2
canShoot = false
local ReloadSound = AnimController.Parent.Sounds.ReloadSound:Clone()
IsAnAnimationPlaying = true
anim:Play()
ReloadSound.Parent = AnimController.Parent.Handle
ReloadSound:Play()
ReloadSound.Ended:Connect(function()
isReloading = false
ReloadSound:Destroy()
end)
local bulletsToSubtract = math.min(defBullets - Values.ActualBullets.Value, Values.TotalBullets.Value)
Values.ActualBullets.Value = Values.ActualBullets.Value + bulletsToSubtract
Values.TotalBullets.Value = Values.TotalBullets.Value - bulletsToSubtract
anim.Ended:Connect(function()
canShoot = true
canReload = true
isReloading = false
IsAnAnimationPlaying = false
end)
anim.Stopped:Connect(function()
canReload = true
end)
end
end
end