Advertisement
mrmrcoder

Identity Fraud Mirror Scripts (MMCK Style)

Apr 25th, 2024
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.35 KB | Source Code | 0 0
  1. --[[
  2. Model: https://create.roblox.com/store/asset/17284321726/MrMr-Coderkids-Mirror
  3.  
  4. These scripts were made for a tutorial, but you may steal it if you wish. ( I don't mind :P )
  5. These scripts improves on Identity Fraud's and Samson's Mirror (Hotel Story Game).
  6.  
  7. These scripts, Instead of reflecting body parts, it reflects *how they move* in comparison to other body parts.
  8. The result is similar to what would happen if you just inverted the way the bones move(for the limbs)
  9. The effect is about the most convincing you can get without inverting a mesh*
  10.  
  11. I hope you enjoy!
  12. Please subscribe? ;-;
  13.  
  14. - ya boy, @mrmrcoderkid(Youtube)
  15.  
  16. *Inverting meshes IS possible, however you cannot enable "DoubleSided" to true at runtime. So it can only be done for preset characters.
  17. --]]
  18.  
  19.  
  20. -- SERVER SCRIPT --
  21.  
  22. local MIRROR_MODULE = require(game.ReplicatedStorage.MMCKmodule)
  23. local mirrors = workspace.MMCK.Mirrors:GetChildren()
  24.  
  25. --[[
  26. This Script is for the player to reflect characters that are in the server.
  27. Since the server, under normal circumstances owns NPCs, then
  28. there is no reason for the Client to handle all of the calculations every frame(.RenderStepped())
  29.  
  30. It is better to do the calculations at PhysicsProcess(.HeartBeat()) to save peformance.
  31. --]]
  32.  
  33. game["Run Service"].Heartbeat:Connect(function()
  34.     for i,mirror in mirrors do
  35.         local _npcs = MIRROR_MODULE.FindNonPlayerCharacters(mirror)
  36.         if _npcs ~= nil then
  37.             for i, npc in _npcs do -- npc reflect loop
  38.                
  39.                 local fake_npc
  40.  
  41.                 if not mirror.fakes:FindFirstChild(npc.Name) then
  42.                     npc.Archivable = true
  43.                    
  44.                     fake_npc = npc:Clone()
  45.                     fake_npc.Name = npc.Name
  46.                     fake_npc.Humanoid.DisplayDistanceType = "None"
  47.                    
  48.                     for i, d in fake_npc:GetChildren() do
  49.                         if d:IsA("BaseScript") then
  50.                             d:Destroy()
  51.                         end
  52.                        
  53.                         if d:IsA("BasePart") then
  54.                             d.Anchored = true
  55.                             d.CanCollide = false
  56.                         end
  57.                     end
  58.                    
  59.                     fake_npc.Parent = mirror.fakes
  60.                     local owner_tag = Instance.new("ObjectValue", fake_npc)
  61.                     owner_tag.Name = "owner"
  62.                     owner_tag.Value = npc
  63.                 else
  64.                     fake_npc = mirror.fakes:FindFirstChild(npc.Name)
  65.                 end
  66.  
  67.  
  68.                 if npc.Humanoid.Health <= 0 or npc == nil then
  69.                     local target = fake_npc or nil
  70.                     if target ~= nil then
  71.                         target:Destroy()
  72.                     end
  73.                 else
  74.                     MIRROR_MODULE:ReflectCharacter(fake_npc, npc, mirror)
  75.                 end
  76.             end
  77.         end
  78.  
  79.         if #mirror.fakes:GetChildren() > 0 then
  80.             for i, fake in mirror.fakes:GetChildren() do -- remove character clones whose owners no longer belong on workspace.
  81.                 if not game.Players:GetPlayerFromCharacter(fake.owner.Value) then
  82.                     if not workspace:FindFirstChild(fake.Name) then
  83.                         fake:Destroy()
  84.                     end
  85.                 end
  86.             end
  87.         end
  88.     end
  89. end)
  90.  
  91. -- END OF SERVER SCRIPT --
  92.  
  93. -- CLIENT SCRIPT --
  94.  
  95. --[[
  96. This script is for reflecting player characters.
  97. Since each player has network ownership of their own characters, they can clone themselves.
  98. This relieves the server from some burdens, saving peformance.
  99. --]]
  100.  
  101. local loaded = false
  102.  
  103.  
  104. -- Proceed only if the character is completely loaded. --
  105. repeat
  106.     wait()
  107. until game.Players.LocalPlayer:HasAppearanceLoaded() == true
  108.  
  109. loaded = true
  110.  
  111. local RunService = game:GetService("RunService")
  112. local camera = workspace.CurrentCamera
  113. local mirrors = workspace.MMCK.Mirrors:GetChildren()
  114. local MIRROR_MODULE = require(game.ReplicatedStorage.MMCKmodule)
  115.  
  116. function get_all_player_characters()
  117.     local list_characters = {}
  118.     for i,plr in game:GetService("Players"):GetPlayers() do
  119.         local char = plr.Character or nil
  120.         if char ~= nil then
  121.             table.insert(list_characters, char)
  122.         end
  123.     end
  124.     return list_characters
  125. end
  126.  
  127. RunService.RenderStepped:Connect(function(dt)
  128.     for i, mirror in mirrors do
  129.         local my_char = game.Players.LocalPlayer.Character
  130.         if (my_char.PrimaryPart.Position - mirror.Position).magnitude < MIRROR_MODULE.range and loaded == true then
  131.             if my_char ~= nil then
  132.                 local plr_characters = get_all_player_characters()
  133.                 if #plr_characters > 0 then
  134.                     for i, plrchar in plr_characters do -- npc reflect loop
  135.                         local fake_plr_name = tostring(plrchar.Name.."_"..game.Players:GetPlayerFromCharacter(my_char).UserId)
  136.                         local fake_npc
  137.  
  138.                         if not mirror.fakes:FindFirstChild(fake_plr_name) then
  139.                             plrchar.Archivable = true
  140.  
  141.                             fake_npc = plrchar:Clone()
  142.                             fake_npc.Name = fake_plr_name
  143.                             fake_npc.Humanoid.DisplayDistanceType = "None"
  144.  
  145.                             for i, d in fake_npc:GetChildren() do
  146.                                 if d:IsA("BaseScript") then
  147.                                     d:Destroy()
  148.                                 end
  149.  
  150.                                 if d:IsA("BasePart") then
  151.                                     d.Anchored = true
  152.                                     d.CanCollide = false
  153.                                 end
  154.                             end
  155.  
  156.                             fake_npc.Parent = mirror.fakes
  157.                             local owner_tag = Instance.new("ObjectValue", fake_npc)
  158.                             owner_tag.Name = "owner"
  159.                             owner_tag.Value = plrchar
  160.                         else
  161.                             fake_npc = mirror.fakes:FindFirstChild(fake_plr_name)
  162.                         end
  163.  
  164.  
  165.                         if plrchar.Humanoid.Health <= 0 or plrchar == nil then
  166.                             local target = fake_npc or nil
  167.                             if target ~= nil then
  168.                                 target:Destroy()
  169.                             end
  170.                         else
  171.                             MIRROR_MODULE:ReflectCharacter(fake_npc, plrchar, mirror)
  172.                         end
  173.                     end
  174.                 end
  175.             end
  176.         end
  177.     end
  178. end)
  179.  
  180. local player = game.Players.LocalPlayer
  181. local char = player.Character or script.Parent
  182. local clone_name = char.Name.."_"..player.UserId
  183.  
  184. char.ChildAdded:Connect(function()
  185.     for i,mirror in mirrors do
  186.         if mirror.fakes:FindFirstChild(clone_name) then
  187.             MIRROR_MODULE:ClearCharacter(mirror, mirror.fakes:FindFirstChild(clone_name))
  188.         end
  189.     end
  190. end)
  191.  
  192. char.ChildRemoved:Connect(function()
  193.     for i,mirror in mirrors do
  194.         if mirror.fakes:FindFirstChild(clone_name) then
  195.             MIRROR_MODULE:ClearCharacter(mirror, mirror.fakes:FindFirstChild(clone_name))
  196.         end
  197.     end
  198. end)
  199.  
  200. -- END OF CLIENT SCRIPT --
  201.  
  202. -- MODULE SCRIPT --
  203. --[[
  204. This is the ModuleScript for the mirror
  205. All that this is is just a "Library" of functions and variables that
  206. can be used by any other script that uses require(ModuleScript)
  207. --]]
  208.  
  209. local mirror_module = {}
  210.  
  211. mirror_module.range = 90 -- how many studs away for mirror to reflect localplayer
  212.  
  213. mirror_module.FindNonPlayerCharacters = function(mirrorPart)
  214.     local range = mirror_module.range
  215.     local npc_list = {}
  216.    
  217.     for i,v in pairs(workspace:GetChildren()) do
  218.         if v:IsA("Model") and v:FindFirstChildOfClass("Humanoid") and not game.Players:GetPlayerFromCharacter(v) then
  219.             table.insert(npc_list, v)
  220.         end
  221.     end
  222.    
  223.     return npc_list
  224. end
  225.  
  226. function mirror_module:ClearCharacter(MIRROR, FAKE_CHAR : Model)
  227.     FAKE_CHAR:Destroy()
  228. end
  229.  
  230. function mirror_module:ReflectPart(FAKE_PART : BasePart, REAL_PART, MIRROR)
  231.     local function reflectCFrame(cframe, mirror) -- THX BADGRAPHIX ON DEVFORUM.
  232.         --Get the CFrame relative to the mirror
  233.         local relCF = mirror.CFrame:toObjectSpace(cframe)
  234.  
  235.         --Get the original CFrame values
  236.         local x, y, z,
  237.         a, b, c,
  238.         d, e, f,
  239.         g, h, i = relCF:components()
  240.  
  241.         --Reflecting along Z direction - negate Z axis on
  242.         --all vectors
  243.         local newCF = CFrame.new(
  244.             x, y, -z,
  245.             a, b, c,
  246.             d, e, f,
  247.             -g, -h, -i
  248.         )
  249.  
  250.         --Convert back to world space
  251.         local finalCFrame = mirror.CFrame:toWorldSpace(newCF)
  252.         local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22 = finalCFrame:components()
  253.        
  254.         finalCFrame = CFrame.new(x, y, z, -r00, r01, r02, -r10, r11, r12, -r20, r21, r22)
  255.        
  256.         return finalCFrame
  257.     end
  258.    
  259.     if FAKE_PART ~= nil then
  260.         FAKE_PART.CFrame = reflectCFrame(REAL_PART.CFrame, MIRROR)
  261.     end
  262. end
  263.  
  264. function mirror_module:ReflectCharacter(FAKE_CHAR, REAL_CHAR, MIRROR)
  265.     if REAL_CHAR.Humanoid.RigType == Enum.HumanoidRigType.R6 then
  266.         mirror_module:ReflectPart(FAKE_CHAR["Head"], REAL_CHAR["Head"], MIRROR)
  267.         mirror_module:ReflectPart(FAKE_CHAR["Torso"], REAL_CHAR["Torso"], MIRROR)
  268.        
  269.        
  270.         mirror_module:ReflectPart(FAKE_CHAR["Left Arm"], REAL_CHAR["Right Arm"], MIRROR)
  271.         mirror_module:ReflectPart(FAKE_CHAR["Right Arm"], REAL_CHAR["Left Arm"], MIRROR)
  272.         mirror_module:ReflectPart(FAKE_CHAR["Left Leg"], REAL_CHAR["Right Leg"], MIRROR)
  273.         mirror_module:ReflectPart(FAKE_CHAR["Right Leg"], REAL_CHAR["Left Leg"], MIRROR)
  274.        
  275.         if FAKE_CHAR["Right Arm"]:FindFirstChild("RightGrip") then
  276.             local weldGrip = FAKE_CHAR["Right Arm"]:FindFirstChild("RightGrip")
  277.             weldGrip.Parent = FAKE_CHAR["Left Arm"]
  278.             weldGrip.Part0 = FAKE_CHAR["Left Arm"]
  279.         end
  280.        
  281.         for i, accessory in REAL_CHAR:GetDescendants() do
  282.             if accessory:IsA("Accessory") then
  283.                 local fake_accessory = FAKE_CHAR:FindFirstChild(accessory.Name)
  284.  
  285.                 if fake_accessory.Handle:FindFirstChild("AccessoryWeld") then
  286.  
  287.                     -- for things like shoulder armour plates
  288.                     if fake_accessory.Handle.AccessoryWeld.Part1 == FAKE_CHAR["Right Arm"] then
  289.                         local fakeWeld = fake_accessory.Handle.AccessoryWeld
  290.                         fakeWeld.Part1 = FAKE_CHAR["Left Arm"]
  291.                         fakeWeld.C0 *= CFrame.Angles(0,-math.rad(-180),0)
  292.                     end
  293.                 end
  294.  
  295.                 -- for shoulder pals
  296.                 if fake_accessory.Handle ~= nil then
  297.                     if fake_accessory.Handle.AccessoryWeld.Part1 == FAKE_CHAR["Torso"] then
  298.                         if fake_accessory.Handle:FindFirstChildOfClass("Weld") then
  299.                             fake_accessory.Handle:FindFirstChildOfClass("Weld").Enabled = false
  300.                             fake_accessory.Handle.Anchored = true
  301.  
  302.                             mirror_module:ReflectPart(fake_accessory.Handle, accessory.Handle, MIRROR)
  303.                         end
  304.                     end
  305.                 end
  306.             end
  307.         end
  308.     end
  309.    
  310.     if REAL_CHAR.Humanoid.RigType == Enum.HumanoidRigType.R15 then
  311.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("Head"), REAL_CHAR:WaitForChild("Head"), MIRROR)
  312.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("UpperTorso"), REAL_CHAR:WaitForChild("UpperTorso"), MIRROR)
  313.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("LowerTorso"), REAL_CHAR:WaitForChild("LowerTorso"), MIRROR)
  314.        
  315.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("RightUpperArm"), REAL_CHAR:WaitForChild("LeftUpperArm"), MIRROR)
  316.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("RightLowerArm"), REAL_CHAR:WaitForChild("LeftLowerArm"), MIRROR)
  317.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("RightHand"), REAL_CHAR:WaitForChild("LeftHand"), MIRROR)
  318.        
  319.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("LeftUpperArm"), REAL_CHAR:WaitForChild("RightUpperArm"), MIRROR)
  320.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("LeftLowerArm"), REAL_CHAR:WaitForChild("RightLowerArm"), MIRROR)
  321.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("LeftHand"), REAL_CHAR:WaitForChild("RightHand"), MIRROR)
  322.        
  323.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("LeftUpperLeg"), REAL_CHAR:WaitForChild("RightUpperLeg"), MIRROR)
  324.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("LeftLowerLeg"), REAL_CHAR:WaitForChild("RightLowerLeg"), MIRROR)
  325.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("LeftFoot"), REAL_CHAR:WaitForChild("RightFoot"), MIRROR)
  326.        
  327.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("RightUpperLeg"), REAL_CHAR:WaitForChild("LeftUpperLeg"), MIRROR)
  328.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("RightLowerLeg"), REAL_CHAR:WaitForChild("LeftLowerLeg"), MIRROR)
  329.         mirror_module:ReflectPart(FAKE_CHAR:WaitForChild("RightFoot"), REAL_CHAR:WaitForChild("LeftFoot"), MIRROR)
  330.        
  331.         if FAKE_CHAR.RightHand:FindFirstChild("RightGrip") then
  332.             local gripWeld = FAKE_CHAR.RightHand:FindFirstChild("RightGrip")
  333.             gripWeld.Parent = FAKE_CHAR.LeftHand
  334.             gripWeld.Part0 = FAKE_CHAR.LeftHand
  335.         end
  336.        
  337.         for i, accessory in REAL_CHAR:GetDescendants() do
  338.             if accessory:IsA("Accessory") then
  339.                 local fake_accessory = FAKE_CHAR:FindFirstChild(accessory.Name)
  340.  
  341.                 if fake_accessory.Handle:FindFirstChild("AccessoryWeld") then
  342.  
  343.                     -- for things like shoulder armour plates
  344.                     if fake_accessory.Handle.AccessoryWeld.Part1 == FAKE_CHAR.RightUpperArm then
  345.                         local fakeWeld = fake_accessory.Handle.AccessoryWeld
  346.                         fakeWeld.Part1 = FAKE_CHAR.LeftUpperArm
  347.                         fakeWeld.C0 *= CFrame.Angles(0,-math.rad(-180),0)
  348.                     end
  349.                 end
  350.  
  351.                 -- for shoulder pals
  352.                 if fake_accessory.Handle ~= nil then
  353.                     if fake_accessory.Handle.AccessoryWeld.Part1 == FAKE_CHAR.UpperTorso then
  354.                         if fake_accessory.Handle:FindFirstChildOfClass("Weld") then
  355.                             fake_accessory.Handle:FindFirstChildOfClass("Weld").Enabled = false
  356.                             fake_accessory.Handle.Anchored = true
  357.  
  358.                             mirror_module:ReflectPart(fake_accessory.Handle, accessory.Handle, MIRROR)
  359.                         end
  360.                     end
  361.                 end
  362.             end
  363.         end
  364.     end
  365. end
  366.  
  367. return mirror_module
  368.  
  369. -- END OF MODULE SCRIPT --
  370.  
  371. -- :3
  372.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement