Mirror script help!

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)

If you want to copy players then why not just do:

for _,player in game.Players:GetPlayers()
	local character = player.Character
end

This would get ONLY the player’s character without having to use some extra code to put the characters in a folder bla bla bla.

1 Like

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

Uh, yes it would? Who told you it won’t lol.

Oh lol, I just thought it wouldn’t as I don’t always use logic
ty for the tip though!

So using your tip, the animations don’t show up in the viewport… (like i thought :confused: )


whereas the script i am using, the animations do

again, all your help is appreciated!

That’s weird. I had something else in my head because when I made something like this it worked with my way…

Okay then why not use a for loop to loop through all the parts of the character and clone them individually?

that probably would work, i’m just not that good at scripting and have no clue how to do that,
which is why I was hoping to use the script I did have :confused:

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)
1 Like

Thank you so much!
after adding a clone command it works perfectly!!!

That’s great. If this post solved it then please mark it as the solution to let others know about it!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.