Viewmodel won't appear

So I’m making a gun system and I’m setting up the viewmodel but when I equip the gun the viewmodel appears in some random place in the workspace instead of in the players camera
anyone know why?

function Gun:Equip()
	print("Gun equipped!")
	self.ViewModel = game.ReplicatedStorage.Viewmodel:Clone()
	self.GunModel = game.ReplicatedStorage.AK74:Clone()

	self.GunModel.Parent = self.ViewModel
	self.ViewModel.Parent = workspace.Camera
	
    local IsFirstPerson = self:CheckFirstPerson()
	
	if self.ViewModel:FindFirstChild("HumanoidRootPart") then
	
		self.ViewModel.PrimaryPart.CFrame = camera.CFrame
		
		print("ViewModel's HumanoidRootPart CFrame set to Camera's CFrame")
	else
		warn("HumanoidRootPart not found in ViewModel!")
	end
	Gun.Equipped = true
end

if you guys need extra details let me know.

2 Likes

It’s probably anchored, or it doesn’t have a handle, or it’s pivot is wrong

1 Like

it’s not anchored already checked that, It has a handle, and its pivot is fine

1 Like

I think you need to update the CFrame every time the camera changes. you could use

game["Run Service"].RenderStepped

or something like that.

I have not got to that part yet Ik it has to be updated every frame but rn it will not appear at all

I would try finishing that part. It might be the source of your problem

just did that nothing changed sadly

Try Turning Off StreamingEnabled on Workspace, and use ViewModel:PivotTo(TargetCFrame) instead of directly changing ViewModel.PrimaryPart.CFrame

nvm I think your pivotTo solution worked

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.