This script checks if there is a tool in the player named "AK47" and if so clones an ak-47 model and changes the model's primary part's CFrame to match the view model. But, the model's CFrame doesn't change even with the command bar. (The arm's viewmodel is changing the CFrame fine).
local player = game.Players.LocalPlayer
local run = game:GetService("RunService")
local cam = game.Workspace.CurrentCamera
game.ReplicatedStorage.DefaultCameraThings.Viewmodel:SetPrimaryPartCFrame(cam.CFrame) -- viewmodel
run.RenderStepped:Connect(function()
cam:WaitForChild("Viewmodel"):SetPrimaryPartCFrame(cam.CFrame * CFrame.new(0.2,-1.4,0.5)) -- matches viewmodel's cframe to the camera
if game.Workspace[player.Name]:FindFirstChild("AK47") then -- checks if there is a tool in the player
game.ReplicatedStorage.GunViewmodel.AK47:Clone().Parent = cam -- change's the model parent to the camera
cam:WaitForChild("AK47"):SetPrimaryPartCFrame(cam.CFrame * CFrame.new(0.2,-1.4,0.5)) -- was supposed to match the model's cframe to the camera but it stays in the ground where i last left it in the workspace
elseif not game.Workspace[player.Name]:FindFirstChild("AK47") and game.Workspace.Camera:FindFirstChild("AK47") then -- if there is no tool in the player and there is still the model for the viewmodel then destroys the model
game.Workspace.Camera.AK47:Destroy()
end
end)
game.ReplicatedStorage.DefaultCameraThings.Viewmodel.Parent = cam -- sets the viewmodel's parent to the camera
