Trying to create a r15 viewmodel to work with guns, but having some issues setting it up.
One of those issues is that the humanoidrootpart wont move to the camerapart’s CFrame.
Heres the code i currently got
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Character.Archivable = true
repeat task.wait() until game:IsLoaded()
local sf = string.find
local viewmodel = Instance.new("Model")
viewmodel.Name = "ViewModel"
local ClonedChar = Character:Clone()
local RootPart
for Num, Part in ipairs(ClonedChar:GetChildren()) do
local name = Part.Name:lower()
if not sf(name, "hand") and not sf(name, "arm") and not sf(name, "head") then
if not Part:IsA("Humanoid") and not Part:IsA("Shirt") and not string.find(Part.Name:lower(), "root") then
Part:Destroy()
elseif Part:IsA("Humanoid") then
Part.Parent = viewmodel
for i, v in ipairs(Part:GetChildren()) do
if not v:IsA("Animator") then v:Destroy()end
end
elseif string.find(Part.Name:lower(), "root") then
RootPart = Part
Part.Parent = nil
Part.Size = Vector3.new(.75,.75,.75)
Part.CanCollide = false
Part.CanQuery = false
Part.CanTouch = false
Part.Transparency = 1
else
Part.Parent = viewmodel
end
else
if not Part:IsA("MeshPart") then
Part:Destroy()
else
Part.Anchored = true
Part.Parent = viewmodel
for i, v in ipairs(Part:GetChildren()) do
if not v:IsA("Motor6D") then
v:Destroy()
end
end
end
end
end
ClonedChar:Destroy()
viewmodel.Parent = workspace.Camera
local Humanoid = viewmodel:WaitForChild("Humanoid")
local CameraPart = Instance.new("Part"); CameraPart.Name = "CameraPart"
CameraPart.Anchored = true
CameraPart.CanCollide = false
CameraPart.Size = Vector3.new(.75,.75,.75)
CameraPart.Parent = viewmodel
CameraPart.CFrame = viewmodel:WaitForChild("Head").CFrame
viewmodel:WaitForChild("Head"):Destroy()
Humanoid.Parent = nil
RootPart.Parent = viewmodel
RootPart.CFrame = CameraPart.CFrame
local LeftHand = viewmodel:WaitForChild("LeftHand")
local LeftLowerArm = viewmodel:WaitForChild("LeftLowerArm")
local LeftUpperArm = viewmodel:WaitForChild("LeftUpperArm")
local RightHand = viewmodel:WaitForChild("RightHand")
local RightLowerArm = viewmodel:WaitForChild("RightLowerArm")
local RightUpperArm = viewmodel:WaitForChild("RightUpperArm")
local Motor1 = Instance.new("Motor6D")
local Motor2 = Instance.new("Motor6D")
local Motor3 = Instance.new("Motor6D")
Motor1.Parent = RootPart
Motor2.Parent = RootPart
Motor3.Parent = RootPart
Motor1.Part0 = RightUpperArm
Motor1.Part1 = RootPart
Motor2.Part0 = LeftUpperArm
Motor2.Part1 = RootPart
Motor3.Part0 = CameraPart
Motor3.Part1 = RootPart
Humanoid.Parent = viewmodel