Hello everyone,
I’m using a script to turn a Tool into a model and then parent it to the viewport, it works if the player hasn’t equipped the tool or moved while equipping it. However, when either of those happen then the tool deform and doesn’t stay in place like this:
(The last 2 tools from the right only show the handle correctly but the other parts aren’t in their right position)
here is the code responsible for changing the tool to a model:
local ViewPort = ViewPortFrame:Clone()
local ViewPortCam = Instance.new("Camera")
local Clone = item:Clone()
local ItemGroup = Instance.new("Model")
--- Needed variables to construct the Viewport ^^^
for i,v in ipairs(Clone:GetChildren()) do -- This will clone the tool and turn it to a model
if v:IsA("BasePart") then
v.Parent = ItemGroup
end
end
Clone:Destroy()
ItemGroup.PrimaryPart = ItemGroup:FindFirstChild("Handle")
ItemGroup.Parent = ViewPort
ItemGroup:PivotTo(CFrame.new(0,0,0) * CFrame.Angles(0,0,0))
ItemGroup:PivotTo(CFrame.new(0,0,0) * CameraSettings.Camera.ModelOrientation)
ViewPort.CurrentCamera = ViewPortCam
ViewPortCam.Parent = ViewPort
ViewPortCam.CameraType = Enum.CameraType.Scriptable
ViewPortCam.CFrame = CFrame.new(ItemGroup:GetPivot().Position + CameraSettings.Camera.Position * CFrame.Angles(0,0,math.rad(35))
ViewPortCam.FieldOfView = CameraSettings.Camera.FOV
-- These are used to adjust the Viewport based on the tool shown ^^^
ViewPort.Parent = slot
Thank you.