Advertisement
Geovanny78970

Highlight Effect Script (Mesh Compatible)

Oct 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.66 KB | None | 0 0
  1. ---//Mesh Compatible//---
  2. local RunService = game:GetService("RunService")
  3.  
  4. local Players = game:GetService("Players")
  5. local Player = Players.LocalPlayer
  6. local Mouse = Player:GetMouse()
  7.  
  8. script.Parent.CurrentCamera = workspace.CurrentCamera
  9.  
  10. local HighlightColors = {
  11.     ["Class1"] = Color3.fromRGB(0,0,255),
  12.     ["Class2"] = Color3.fromRGB(255,0,0),
  13.     ["Class3"] = Color3.fromRGB(0,255,0),
  14. }
  15.  
  16. local DefaultHighlightColor = Color3.fromRGB(255,255,0)
  17.  
  18. local ObjectToHighlight
  19. local ObjectProperties = {
  20.     Color = nil,
  21.     Material = nil,
  22.     Texture = nil,
  23. }
  24. local ObjectClone
  25.  
  26. local function SetTarget(Target, Class)
  27.     if ObjectToHighlight and ObjectToHighlight ~= Target then
  28.         if ObjectToHighlight:IsA("MeshPart") then
  29.             ObjectToHighlight.TextureID = ObjectProperties.Texture
  30.         end
  31.         ObjectToHighlight.Color = ObjectProperties.Color
  32.         ObjectToHighlight.Material = ObjectProperties.Material
  33.        
  34.         ObjectProperties.Color = nil
  35.         ObjectProperties.Material = nil
  36.         ObjectProperties.Texture = nil
  37.        
  38.         ObjectClone:Destroy()
  39.    
  40.         ObjectToHighlight = nil
  41.         ObjectClone = nil
  42.     elseif ObjectToHighlight and ObjectToHighlight == Target then
  43.         return
  44.     end
  45.    
  46.     ObjectToHighlight = Target
  47.     ObjectProperties.Color = ObjectToHighlight.Color
  48.     ObjectProperties.Material = ObjectToHighlight.Material
  49.     if ObjectToHighlight:IsA("MeshPart") then
  50.         ObjectProperties.Texture = ObjectToHighlight.TextureID
  51.     end
  52.     ObjectClone = ObjectToHighlight:Clone()
  53.     print("Target and Clone set")
  54.    
  55.     if Class then
  56.         ObjectToHighlight.Color = HighlightColors[Class]
  57.     else
  58.         ObjectToHighlight.Color = DefaultHighlightColor
  59.     end
  60.    
  61.     ObjectClone.Anchored = true
  62.     ObjectClone.Parent = script.Parent
  63.     ObjectClone.CFrame = Target.CFrame
  64.    
  65.     ObjectToHighlight.Material = Enum.Material.Neon
  66.     if ObjectToHighlight:IsA("MeshPart") then
  67.         ObjectToHighlight.TextureID = ""
  68.     end
  69.    
  70.     UpdateCFrame = RunService.RenderStepped:Connect(function()
  71.         if ObjectToHighlight and ObjectClone then
  72.             ObjectClone.CFrame = ObjectToHighlight.CFrame
  73.         else
  74.             UpdateCFrame:Disconnect()
  75.         end
  76.     end)
  77. end
  78.  
  79. local function UnsetTarget()
  80.     if ObjectToHighlight and ObjectClone then
  81.         if ObjectToHighlight:IsA("MeshPart") then
  82.             ObjectToHighlight.TextureID = ObjectProperties.Texture
  83.         end
  84.         ObjectToHighlight.Color = ObjectProperties.Color
  85.         ObjectToHighlight.Material = ObjectProperties.Material
  86.        
  87.         ObjectClone:Destroy()
  88.     end
  89.    
  90.     ObjectProperties.Color = nil
  91.     ObjectProperties.Material = nil
  92.     ObjectProperties.Texture = nil
  93.        
  94.     ObjectToHighlight = nil
  95.     ObjectClone = nil
  96. end
  97.  
  98. while wait() do
  99.     if Mouse.Target and Mouse.Target.Name == "TestPart" then
  100.         SetTarget(Mouse.Target)
  101.     else
  102.         UnsetTarget()
  103.     end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement