Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- StarterGUI:
- -- LocalScript:
- -- Name The LocalScript: mirrors
- local player = game:GetService("Players").LocalPlayer
- local character; repeat wait() character = player.Character until character
- local camera = game:GetService("Workspace").CurrentCamera
- local rs = game:GetService("RunService").RenderStepped
- local reflections = require(script:WaitForChild("reflections"))
- local mirrors = game:GetService("Workspace"):WaitForChild("Mirror model")
- rs:connect(function()
- reflections:clearCharacters()
- local characters = {}
- for _, player in pairs(game:GetService("Players"):GetPlayers()) do
- table.insert(characters, player.Character)
- end
- for _, mirror in pairs(mirrors:GetChildren()) do
- if mirror:IsA("BasePart") then
- reflections:drawWorld(mirror, game:GetService("Workspace"), {mirrors, unpack(characters)})
- reflections:drawCharacters(characters, mirror)
- end
- end
- end)
- -- ModuleScript:
- -- Name The ModuleScript: reflections
- local class = {}
- local camera = game:GetService("Workspace").CurrentCamera
- local renderPacket = {}
- local reflections = Instance.new("Model", camera)
- local users = Instance.new("Model", reflections)
- local environment = Instance.new("Model", reflections)
- reflections.Name = "reflections"
- users.Name = "users"
- environment.Name = "environment"
- --// Functions
- function gather(children, class, tab)
- local tab = tab and tab or {}
- for _, child in pairs(children) do
- if child:IsA(class) then
- table.insert(tab, child)
- end
- tab = gather(type(child) == "table" and child or child:GetChildren(), class, tab)
- end
- return tab
- end
- function gather_Ignores(children, class, ignores)
- local tab = {}
- for _, part in pairs(gather(children, class)) do
- local pass = true
- for _, thing in pairs(ignores) do
- if part == thing or part:IsDescendantOf(thing) then
- pass = false
- end
- end
- if pass then
- table.insert(tab, part)
- end
- end
- return tab
- end
- --// Methods
- function class:reflect(item, against)
- local cf = item:IsA("BasePart") and item.CFrame or item.PrimaryPart.CFrame
- local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21,r22 = against.CFrame:toObjectSpace(cf):components()
- local newCf = against.CFrame:toWorldSpace(CFrame.new(-x ,y ,z , r00, -r01, -r02, -r10, r11, r12, -r20, r21, r22))
- if item:IsA("BasePart") then
- item.CFrame = newCf
- if item:IsA("CornerWedgePart") then
- item.Size = Vector3.new(item.Size.z, item.Size.y, item.Size.x)
- item.CFrame = item.CFrame * CFrame.Angles(0,math.rad(90),0)
- end
- elseif item:IsA("Model") then
- item:SetPrimaryPartCFrame(newCf)
- end
- end
- function class:drawWorld(against, parent, ignores)
- table.insert(ignores, camera)
- local renders = gather_Ignores({parent}, "BasePart", ignores)
- renderPacket[against] = renderPacket[against] or {}
- for _, part in pairs(renders) do
- if (not part.Locked or part.Parent:IsA("Hat")) and part.Transparency < 1 then
- if not renderPacket[against][part] or renderPacket[against][part].cf ~= part.CFrame then
- if renderPacket[against][part] then
- renderPacket[against][part].focus:Destroy()
- end
- local focus = part:Clone()
- local joints = gather(focus:GetChildren(), "JointInstance")
- for _, joint in pairs(joints) do joint:Destroy() end
- focus.Anchored = true
- self:reflect(focus, against)
- focus.Parent = environment
- renderPacket[against][part] = {
- cf = part.CFrame;
- origin = part;
- focus = focus;
- event = part.AncestryChanged:connect(function() focus:Destroy() end);
- }
- end
- end
- end
- end
- function class:drawCharacters(characters, against)
- for _, character in pairs(characters) do
- character.Archivable = true
- local character = character:Clone()
- local hum = character:FindFirstChild("Humanoid")
- local scripts = gather(character:GetChildren(), "BaseScript")
- local parts = gather(character:GetChildren(), "BasePart")
- local joints = gather(character:GetChildren(), "JointInstance")
- if hum then
- hum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
- end
- for _, src in pairs(scripts) do src:Destroy() end
- for _, joint in pairs(joints) do joint:Destroy() end
- for _, part in pairs(parts) do
- part.Anchored = true
- part.CanCollide = false
- self:reflect(part, against)
- end
- character.Parent = users
- end
- end
- function class:clearCharacters()
- users:ClearAllChildren()
- end
- function class:cleanup()
- environment:ClearAllChildren()
- users:ClearAllChildren()
- renderPacket = {}
- end
- return class
- -- Made by Youtube.com/c/StillwaterYT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement