FPS/TPS tools randomly deleting themselves from player inventory

Hello,

I have a weapon system that can be used in third person and first person. When the player is in first person, the viewmodel is parented to their camera and the RightGrip of the tool is set to the hand of the viewmodel using this code in a renderstep event inside the tool:

function CheckFirstPerson()
	if Character.Head.LocalTransparencyModifier > 0.6 then
		return true
               -- in first person
	else 
		return false
	end
end


--inside renderstep function
local RightGrip = Character.RightHand:WaitForChild("RightGrip");
		local InFirstPerson = CheckFirstPerson();
		if InFirstPerson and RightGrip.Part0 ~= ViewModel.RightHand then
			RightGrip.Part0 = ViewModel.RightHand;
			print("Set grip to viewmodel")
			ViewModel.Parent = Camera;
		end
		if not InFirstPerson and RightGrip.Part0 ~= Character.RightHand then
			RightGrip.Part0 = Character.RightHand;
			print("Set grip to character")
			ViewModel.Parent = ViewModelStorage;
		end

The viewmodel CFrame is set to the camera CFrame in a separate local script using a renderstep event with the following code:

RunService:BindToRenderStep("Viewmodel", 301, function(DT)
	if ViewModel.Parent == Camera then
	local MouseDelta = UserInputService:GetMouseDelta();
	MouseSway.Velocity += Vector3.new(MouseDelta.X/MouseSwayIntensity, MouseDelta.Y/MouseSwayIntensity)
	local MovementSwayAmount = Vector3.new(GetBobbing(10, 1, .2), GetBobbing(5, 1, .2), GetBobbing(5, 1, .2))
	MovementSway.Velocity += ((MovementSwayAmount/MovementSwayIntensity) * DT * 60 * HumanoidRootPart.AssemblyLinearVelocity.Magnitude);
	ViewModel:SetPrimaryPartCFrame(
		    Camera.CFrame * CFrame.new(MovementSway.Position.X/2, MovementSway.Position.Y/2, 0)
			* CFrame.Angles(0, -MouseSway.Position.X, MouseSway.Position.Y)
			* CFrame.Angles(0, MovementSway.Position.Y, MovementSway.Position.X)
			* Offset.Value
	        )
	end
end)

this system works perfectly fine I suppose, but for some reason the tool randomly removes itself from the backpack with no apparent relation to player actions such as running, aiming, jumping, shooting etc. I don’t know if this is due to the fact that the RightGrip.Part0 changes multiple times after equipping the tool (as the player changes from first to third person)? I just wanted to search for some solutions here before I commit to completely redesigning the viewmodel system.