Greetings.
So, a friend of mine created a script for a Locker GUI, where the player can choose their accessories and then there is a copy of a player in the GUI, something like a preview, of how the player will look.
The problem: The arms and legs of the copy of the player stay in the same rotation as the real player is currently in, while the head and the body rotate as needed, and we cant really figure out how to fix that.
Has anyone an idea? I will leave a part of the code down here and a image showing the problem.
local function ReplicateChar()
player.Character.Archivable = true
repeat wait() until player.Character:FindFirstChild("Torso")
for i,v in pairs(player.Character:GetDescendants()) do
v.Archivable = true
end
local newChar = character:Clone()
for i,v in pairs(newChar:GetChildren()) do
if v:IsA("Model") or v:IsA("Accessory") or v:IsA("Tool") then
v:Destroy()
end
end
if newChar:FindFirstChild("Saude") then
newChar.Saude:Destroy()
end
newChar.Parent = workspace.xgWorkspace
for i,v in pairs(CurrentEquipped) do
if i == "Chest" then
for _,x in pairs(v:GetChildren()) do
modules[i].Equip(player, x, true)
end
else
modules[i].Equip(player, v, true)
end
end
return(newChar)
end
local function InitChar()
for i,v in pairs(CurrentEquipped) do
print(i,v)
end
spawn(function()
for i,v in pairs(preview.RenderFrame:GetChildren()) do
v:Destroy()
end
local newchar = ReplicateChar()
newchar:SetPrimaryPartCFrame(CFrame.new(newchar.PrimaryPart.Position) * CFrame.Angles(0, 180, 0))
newchar.Parent = preview.RenderFrame
local VPP = Vector3.new(0,0,0)
local itemCam = Instance.new("Camera",preview.RenderFrame)
preview.RenderFrame.CurrentCamera = itemCam
local currentAngle = 0
local modelCF, modelSize = newchar:GetBoundingBox()
local rotInv = (modelCF - modelCF.p):inverse()
modelCF = modelCF
modelSize = rotInv * modelSize
modelSize = Vector3.new(math.abs(modelSize.x), math.abs(modelSize.y), math.abs(modelSize.z))
local diagonal = 0
local maxExtent = math.max(modelSize.x, modelSize.y, modelSize.z)
local tan = math.tan(math.rad(itemCam.FieldOfView/2))
if (maxExtent == modelSize.x) then
diagonal = math.sqrt(modelSize.y*modelSize.y + modelSize.z*modelSize.z)/2
elseif (maxExtent == modelSize.y) then
diagonal = math.sqrt(modelSize.x*modelSize.x + modelSize.z*modelSize.z)/2
else
diagonal = math.sqrt(modelSize.x*modelSize.x + modelSize.y*modelSize.y)/2
end
local minDist = (maxExtent/2)/tan + diagonal
local Scale = 1500
local Center = Vector2.new(workspace.CurrentCamera.ViewportSize.X / 2, workspace.CurrentCamera.ViewportSize.Y / 2 - (game:GetService("GuiService"):GetGuiInset().Y/2))
local MoveVector = Vector3.new((Mouse.X-Center.X)/Scale, -(Mouse.Y-Center.Y)/Scale, 0)
itemCam.CFrame = modelCF * CFrame.fromEulerAnglesYXZ((-(Mouse.Y-Center.Y)/Scale),(-(Mouse.X-Center.X)/Scale)+math.rad(180), 0) * CFrame.new(0, 0, minDist)
local function Update()
if newchar == nil then return end
itemCam.CFrame = modelCF * CFrame.fromEulerAnglesYXZ((-(Mouse.Y-Center.Y)/Scale),(-(Mouse.X-Center.X)/Scale)+math.rad(180), 0) * CFrame.new(0, 0, minDist) ---(Mouse.X-Center.X)/Scale
end
Mouse.Move:Connect(Update)
end)
end
^ The part of the code where the copy of the player is created.