Hello Im making a ViewportFrame that will display the player’s character and I have a script that is intended to make that happen however Im getting an unusual error that I cannot seem to solve.
Script:
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local MouseInDisplay, HoldInDisplay = false, false
local CurrentX
local VPFcam = Instance.new("Camera"); VPFcam.Parent = script.Parent.InventoryFrame.CharacterVport
VPFcam.CFrame = CFrame.new(0,0,0)
script.Parent.InventoryFrame.CharacterVport.CurrentCamera = VPFcam
repeat wait(.1) until game:IsLoaded()
Character.Archivable = true
local ClonedChar = Character:Clone()
ClonedChar.Parent = script.Parent.InventoryFrame.CharacterVport.WorldModel
ClonedChar.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
ClonedChar:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,-9.5), Vector3.new(0,0,0)))
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if MouseInDisplay == true then
HoldInDisplay = true
CurrentX = nil
end
end
end)
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
HoldInDisplay = false
end
end)
script.Parent.InventoryFrame.CharacterVport.MouseMoved:Connect(function(X,Y)
if HoldInDisplay == false then
return
end
if CurrentX then
ClonedChar.PrimaryPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,((X - CurrentX)*.025),0)
end
CurrentX = X
end)
script.Parent.InventoryFrame.CharacterVport.MouseEnter:Connect(function()
MouseInDisplay = true
end)
script.Parent.InventoryFrame.CharacterVport.MouseLeave:Connect(function()
MouseInDisplay = false
end)