Hello! I am making a mirror with a viewport frame
for the most part it works, however I would like it to only copy players rather than every part
Here is the original script (this works about 50% of the time…)
local gui = script.Parent
local ViewportCamera = Instance.new("Camera")
ViewportCamera.CFrame = gui.Adornee.Parent.CameraDirection.CFrame
ViewportCamera.FieldOfView = 70
gui.ViewportFrame.CurrentCamera = ViewportCamera
local RunService = game:GetService("RunService")
local DetectZone:BasePart = gui.Adornee.Parent.Detection
RunService.Heartbeat:Connect(function(step)
gui.ViewportFrame.WorldModel:ClearAllChildren()
local parts = workspace:GetPartBoundsInBox(DetectZone.CFrame, DetectZone.Size)
for _, part in parts do
local clone = part:Clone()
clone.Parent = gui.ViewportFrame.WorldModel
end
end)
To (attempt to) have it select only players I made a script to put all players into a folder as they join the game
on line 14 i added “PlayerFolder” (the name of the folder) after “workspace” to have it only look for parts / players and that gives me an error
Players.BallOTinfoil.PlayerGui.SurfaceGui.the automatic one:15: attempt to iterate over a nil value
clicking on the error doesn’t show me anything or how to fix it
so i’m thinking I must’ve used the wrong solution
Any ideas how to properly have it only find players would be appreciated!
local gui = script.Parent
local ViewportCamera = Instance.new("Camera")
ViewportCamera.CFrame = gui.Adornee.Parent.CameraDirection.CFrame
ViewportCamera.FieldOfView = 70
gui.ViewportFrame.CurrentCamera = ViewportCamera
local RunService = game:GetService("RunService")
local DetectZone:BasePart = gui.Adornee.Parent.Detection
RunService.Heartbeat:Connect(function(step)
gui.ViewportFrame.WorldModel:ClearAllChildren()
local parts = workspace.PlayerFolder:GetPartBoundsInBox(DetectZone.CFrame, DetectZone.Size)
for _, part in parts do
local clone = part:Clone()
clone.Parent = gui.ViewportFrame.WorldModel
end
end)
tyy!!
(script above is almost the exact same but has “PlayerFolder”, this one will have an error every time)
copying the player’s character directly wouldn’t work as then the it doesn’t copy the exact position of each limb to show the illusion of animation (I could be wrong though)
I can send a copy of the .rbxl if it’ll help
local gui = script.Parent
local ViewportCamera = Instance.new("Camera")
ViewportCamera.CFrame = gui.Adornee.Parent.CameraDirection.CFrame
ViewportCamera.FieldOfView = 70
gui.ViewportFrame.CurrentCamera = ViewportCamera
local RunService = game:GetService("RunService")
local DetectZone:BasePart = gui.Adornee.Parent.Detection
RunService.Heartbeat:Connect(function(step)
gui.ViewportFrame.WorldModel:ClearAllChildren()
for _,player in game.Players:GetPlayers() do
for _,part in player.Character:GetChildren() do
-- Do the cframe and stuff.
end
end)
end)