I have a gun system with aim down sights but when i aim the gun goes out of the camera. Code
local viewmodel = game.Workspace:WaitForChild("MODEL")
local player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
viewmodel.Parent = cam
local mouse = player:GetMouse()
local animation = script:WaitForChild("Hold")
local Humanoid = viewmodel.Humanoid
local Animation = Humanoid:LoadAnimation(animation)
local run = game:GetService("RunService")
Animation:Play()
local aiming = false
local posAIM = CFrame.new()
run.RenderStepped:Connect(function()
viewmodel:SetPrimaryPartCFrame(cam.CFrame * posAIM)
if aiming then
posAIM = posAIM:Lerp(cam.CFrame,0.2) --Goal CFrame (lower the number, lower the speed is)
else
posAIM = posAIM:Lerp(CFrame.new(), 0.1)
end
end)
mouse.Button2Down:Connect(function()
viewmodel.PrimaryPart = viewmodel.Val.Aim
aiming = true
end)
mouse.Button2Up:Connect(function()
viewmodel.PrimaryPart = viewmodel.HumanoidRootPart
aiming = false
end)
help please