Gun randomly disappearing?

My viewmodel gun always disappears on the player death, the gun is still connected to the camera but the transparency is still 1, anyone know how I could fix this?
Transparency Script:

local function OnRenderStepped()
	if (Camera.CFrame.Position - Head.Position).Magnitude < 0.8 then
		for index, instance in pairs(script.Parent:GetDescendants()) do 
			if instance:IsA("BasePart") then
				instance.Transparency = 0
				script.Parent["Left Arm"].Decal.LocalTransparencyModifier = 0
				script.Parent["Right Arm"].Decal.LocalTransparencyModifier = 0
				script.Parent["Left Arm"].Decal.Transparency = 0
				script.Parent["Right Arm"].Decal.Transparency = 0
				instance.LocalTransparencyModifier = 0
			end
		end
	end
	if (Camera.CFrame.Position - Head.Position).Magnitude > 0.8 then
		for index, instance in pairs(script.Parent:GetDescendants()) do 
			if instance:IsA("BasePart") then
				instance.Transparency = 1
				script.Parent["Left Arm"].Decal.LocalTransparencyModifier = 1
				script.Parent["Right Arm"].Decal.LocalTransparencyModifier = 1
				script.Parent["Left Arm"].Decal.Transparency = 1
				script.Parent["Right Arm"].Decal.Transparency = 1
				instance.LocalTransparencyModifier = 1
			end
		end
	end
end
1 Like