Advertisement
Geovanny78970

Highlight Effect Script (Models Compatible)

Oct 19th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.29 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local ContentProvider = game:GetService("ContentProvider")
  3. local Workspace = game:GetService("Workspace")
  4. local Camera = Workspace.CurrentCamera
  5.  
  6. local Players = game:GetService("Players")
  7. local Player = Players.LocalPlayer
  8. local Character = Player.Character or Player.CharacterAdded:Wait()
  9. local Mouse = Player:GetMouse()
  10.  
  11. script.Parent.CurrentCamera = Workspace.CurrentCamera
  12.  
  13. local HighlightColors = {
  14.     ["Class1"] = Color3.fromRGB(0, 0, 255),
  15.     ["Class2"] = Color3.fromRGB(255, 0, 0),
  16.     ["Class3"] = Color3.fromRGB(0, 255, 0),
  17.     ["Class4"] = Color3.fromRGB(255, 255, 255)
  18. }
  19.  
  20. local DefaultHighlightColor = Color3.fromRGB(255,255,0)
  21.  
  22. local ObjectToHighlight
  23. local ObjectProperties = {}
  24. local ObjectClone
  25. local ModelObjects = {} --Used just if the Object To Highlight is a Model
  26.  
  27. local function UnsetTarget()
  28.     if ObjectToHighlight and ObjectClone then
  29.         if ObjectToHighlight:IsA("MeshPart") then
  30.             ObjectToHighlight.TextureID = ObjectProperties.Texture
  31.             ObjectToHighlight.Color = ObjectProperties.Color
  32.             ObjectToHighlight.Material = ObjectProperties.Material
  33.         elseif ObjectToHighlight:IsA("UnionOperation") then
  34.             ObjectToHighlight.UsePartColor = ObjectProperties.UsePartColor
  35.             ObjectToHighlight.Color = ObjectProperties.Color
  36.             ObjectToHighlight.Material = ObjectProperties.Material
  37.         elseif ObjectToHighlight:IsA("Model") then
  38.             for _,Object in pairs (ObjectToHighlight:GetDescendants()) do
  39.                 if ModelObjects[Object.Name] then
  40.                     if Object:IsA("MeshPart") then
  41.                         Object.TextureID = ModelObjects[Object.Name].Texture
  42.                         Object.Color = ModelObjects[Object.Name].Color
  43.                         Object.Material = ModelObjects[Object.Name].Material
  44.                     elseif Object:IsA("UnionOperation") then
  45.                         Object.UsePartColor = ModelObjects[Object.Name].UsePartColor
  46.                         Object.Color = ModelObjects[Object.Name].Color
  47.                         Object.Material = ModelObjects[Object.Name].Material
  48.                     elseif Object:IsA("BasePart") or Object:IsA("Part") then
  49.                         Object.Color = ModelObjects[Object.Name].Color
  50.                         Object.Material = ModelObjects[Object.Name].Material
  51.                     end
  52.                 end
  53.             end
  54.         elseif ObjectToHighlight:IsA("BasePart") or ObjectToHighlight:IsA("Part") then
  55.             ObjectToHighlight.Color = ObjectProperties.Color
  56.             ObjectToHighlight.Material = ObjectProperties.Material
  57.         end
  58.        
  59.         ObjectClone:Destroy()
  60.     end
  61.    
  62.     if #ObjectProperties > 0 then
  63.         table.foreach(ObjectProperties, table.remove)
  64.     end
  65.    
  66.     if #ModelObjects > 0 then
  67.         table.foreach(ModelObjects, table.remove)
  68.     end
  69.        
  70.     ObjectToHighlight = nil
  71.     ObjectClone = nil
  72. end
  73.  
  74. local function SetModelAsTarget(Model, Class)
  75.     if ObjectToHighlight and ObjectToHighlight ~= Model then
  76.         UnsetTarget()
  77.     elseif ObjectToHighlight == Model then
  78.         return
  79.     end
  80.    
  81.     ObjectToHighlight = Model
  82.    
  83.     for _,Object in pairs (ObjectToHighlight:GetDescendants()) do
  84.         if Object:IsA("MeshPart") then
  85.             ModelObjects[Object.Name] = {}
  86.             ModelObjects[Object.Name]["Texture"] = Object.TextureID
  87.             ModelObjects[Object.Name]["Color"] = Object.Color
  88.             ModelObjects[Object.Name]["Material"] = Object.Material
  89.         elseif Object:IsA("UnionOperation") then
  90.             ModelObjects[Object.Name] = {}
  91.             ModelObjects[Object.Name]["UsePartColor"] = Object.UsePartColor
  92.             ModelObjects[Object.Name]["Color"] = Object.Color
  93.             ModelObjects[Object.Name]["Material"] = Object.Material
  94.         elseif Object:IsA("BasePart") or Object:IsA("Part") then
  95.             ModelObjects[Object.Name] = {}
  96.             ModelObjects[Object.Name]["Color"] = Object.Color
  97.             ModelObjects[Object.Name]["Material"] = Object.Material
  98.         end
  99.     end
  100.    
  101.     ObjectClone = ObjectToHighlight:Clone()
  102.  
  103.     for _,Object in pairs (ObjectClone:GetDescendants()) do
  104.         if Object:IsA("MeshPart") or Object:IsA("UnionOperation") or Object:IsA("BasePart") or Object:IsA("Part") then
  105.             Object.Anchored = true
  106.         end
  107.     end
  108.    
  109.     for _,Object in pairs (ObjectClone:GetDescendants()) do
  110.         if Object:IsA("MeshPart") or Object:IsA("UnionOperation") or Object:IsA("BasePart") or Object:IsA("Part") then
  111.             Object.CFrame = ObjectToHighlight:FindFirstChild(Object.Name).CFrame
  112.         end
  113.     end
  114.     ObjectClone.Parent = script.Parent
  115.    
  116.     ContentProvider:PreloadAsync({ObjectClone})
  117.    
  118.     for _,Object in pairs (ObjectToHighlight:GetDescendants()) do
  119.         if Object:IsA("MeshPart") then
  120.             Object.TextureID = ""
  121.             Object.Color = HighlightColors[Class] or DefaultHighlightColor
  122.             Object.Material = Enum.Material.Neon
  123.         elseif Object:IsA("UnionOperation") then
  124.             Object.UsePartColor = true
  125.             Object.Color = HighlightColors[Class] or DefaultHighlightColor
  126.             Object.Material = Enum.Material.Neon
  127.         elseif Object:IsA("BasePart") or Object:IsA("Part") then
  128.             Object.Color = HighlightColors[Class] or DefaultHighlightColor
  129.             Object.Material = Enum.Material.Neon
  130.         end
  131.     end
  132.    
  133.     Connection = RunService.RenderStepped:Connect(function()
  134.         if ObjectToHighlight and ObjectClone then
  135.             for _,Object in pairs (ObjectClone:GetDescendants()) do
  136.                 if Object:IsA("MeshPart") or Object:IsA("UnionOperation") or Object:IsA("BasePart") or Object:IsA("Part") then
  137.                     Object.CFrame = ObjectToHighlight:FindFirstChild(Object.Name).CFrame
  138.                 end
  139.             end
  140.         else
  141.             Connection:Disconnect()
  142.         end
  143.     end)
  144. end
  145.  
  146. local function SetTarget(Target, Class)
  147.     if ObjectToHighlight and ObjectToHighlight ~= Target then
  148.         UnsetTarget()
  149.     elseif ObjectToHighlight and ObjectToHighlight == Target then
  150.         return
  151.     end
  152.    
  153.     ObjectToHighlight = Target
  154.    
  155.     if ObjectToHighlight:IsA("MeshPart") and ObjectToHighlight.Texture then
  156.         ObjectProperties["Texture"] = ObjectToHighlight.TextureID
  157.     elseif ObjectToHighlight:IsA("UnionOperation") then
  158.         ObjectProperties["UsePartColor"] = ObjectToHighlight.UsePartColor
  159.     end
  160.  
  161.     ObjectProperties["Color"] = ObjectToHighlight.Color
  162.     ObjectProperties["Material"] = ObjectToHighlight.Material
  163.    
  164.     ObjectClone = ObjectToHighlight:Clone()
  165.     print("Target and Clone set")
  166.    
  167.     ObjectClone.Anchored = true
  168.     ObjectClone.CFrame = ObjectToHighlight.CFrame
  169.     ObjectClone.Parent = script.Parent
  170.    
  171.     ContentProvider:PreloadAsync({ObjectClone})
  172.    
  173.     if Class and HighlightColors[Class] then
  174.         ObjectToHighlight.Color = HighlightColors[Class]
  175.     else
  176.         ObjectToHighlight.Color = DefaultHighlightColor
  177.     end
  178.    
  179.     if ObjectToHighlight:IsA("MeshPart") then
  180.         ObjectToHighlight.TextureID = ""
  181.     elseif ObjectToHighlight:IsA("UnionOperation") then
  182.         ObjectToHighlight.UsePartColor = true
  183.     end
  184.    
  185.     ObjectToHighlight.Material = Enum.Material.Neon
  186.    
  187.     UpdateCFrame = RunService.RenderStepped:Connect(function()
  188.         if ObjectToHighlight and ObjectClone then
  189.             ObjectClone.CFrame = ObjectToHighlight.CFrame
  190.         else
  191.             UpdateCFrame:Disconnect()
  192.         end
  193.     end)
  194. end
  195.  
  196. while true do
  197.     if Mouse.Target and Mouse.Target.Name == "TestPart" then
  198.         if Mouse.Target.Parent:IsA("Model") then
  199.             SetModelAsTarget(Mouse.Target.Parent)
  200.         else
  201.             SetTarget(Mouse.Target)
  202.         end
  203.     else
  204.         UnsetTarget()
  205.     end
  206.     wait()
  207. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement