Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RunService = game:GetService("RunService")
- local ContentProvider = game:GetService("ContentProvider")
- local Workspace = game:GetService("Workspace")
- local Camera = Workspace.CurrentCamera
- local Players = game:GetService("Players")
- local Player = Players.LocalPlayer
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local Mouse = Player:GetMouse()
- script.Parent.CurrentCamera = Workspace.CurrentCamera
- local HighlightColors = {
- ["Class1"] = Color3.fromRGB(0, 0, 255),
- ["Class2"] = Color3.fromRGB(255, 0, 0),
- ["Class3"] = Color3.fromRGB(0, 255, 0),
- ["Class4"] = Color3.fromRGB(255, 255, 255)
- }
- local DefaultHighlightColor = Color3.fromRGB(255,255,0)
- local ObjectToHighlight
- local ObjectProperties = {}
- local ObjectClone
- local ModelObjects = {} --Used just if the Object To Highlight is a Model
- local function UnsetTarget()
- if ObjectToHighlight and ObjectClone then
- if ObjectToHighlight:IsA("MeshPart") then
- ObjectToHighlight.TextureID = ObjectProperties.Texture
- ObjectToHighlight.Color = ObjectProperties.Color
- ObjectToHighlight.Material = ObjectProperties.Material
- elseif ObjectToHighlight:IsA("UnionOperation") then
- ObjectToHighlight.UsePartColor = ObjectProperties.UsePartColor
- ObjectToHighlight.Color = ObjectProperties.Color
- ObjectToHighlight.Material = ObjectProperties.Material
- elseif ObjectToHighlight:IsA("Model") then
- for _,Object in pairs (ObjectToHighlight:GetDescendants()) do
- if ModelObjects[Object.Name] then
- if Object:IsA("MeshPart") then
- Object.TextureID = ModelObjects[Object.Name].Texture
- Object.Color = ModelObjects[Object.Name].Color
- Object.Material = ModelObjects[Object.Name].Material
- elseif Object:IsA("UnionOperation") then
- Object.UsePartColor = ModelObjects[Object.Name].UsePartColor
- Object.Color = ModelObjects[Object.Name].Color
- Object.Material = ModelObjects[Object.Name].Material
- elseif Object:IsA("BasePart") or Object:IsA("Part") then
- Object.Color = ModelObjects[Object.Name].Color
- Object.Material = ModelObjects[Object.Name].Material
- end
- end
- end
- elseif ObjectToHighlight:IsA("BasePart") or ObjectToHighlight:IsA("Part") then
- ObjectToHighlight.Color = ObjectProperties.Color
- ObjectToHighlight.Material = ObjectProperties.Material
- end
- ObjectClone:Destroy()
- end
- if #ObjectProperties > 0 then
- table.foreach(ObjectProperties, table.remove)
- end
- if #ModelObjects > 0 then
- table.foreach(ModelObjects, table.remove)
- end
- ObjectToHighlight = nil
- ObjectClone = nil
- end
- local function SetModelAsTarget(Model, Class)
- if ObjectToHighlight and ObjectToHighlight ~= Model then
- UnsetTarget()
- elseif ObjectToHighlight == Model then
- return
- end
- ObjectToHighlight = Model
- for _,Object in pairs (ObjectToHighlight:GetDescendants()) do
- if Object:IsA("MeshPart") then
- ModelObjects[Object.Name] = {}
- ModelObjects[Object.Name]["Texture"] = Object.TextureID
- ModelObjects[Object.Name]["Color"] = Object.Color
- ModelObjects[Object.Name]["Material"] = Object.Material
- elseif Object:IsA("UnionOperation") then
- ModelObjects[Object.Name] = {}
- ModelObjects[Object.Name]["UsePartColor"] = Object.UsePartColor
- ModelObjects[Object.Name]["Color"] = Object.Color
- ModelObjects[Object.Name]["Material"] = Object.Material
- elseif Object:IsA("BasePart") or Object:IsA("Part") then
- ModelObjects[Object.Name] = {}
- ModelObjects[Object.Name]["Color"] = Object.Color
- ModelObjects[Object.Name]["Material"] = Object.Material
- end
- end
- ObjectClone = ObjectToHighlight:Clone()
- for _,Object in pairs (ObjectClone:GetDescendants()) do
- if Object:IsA("MeshPart") or Object:IsA("UnionOperation") or Object:IsA("BasePart") or Object:IsA("Part") then
- Object.Anchored = true
- end
- end
- for _,Object in pairs (ObjectClone:GetDescendants()) do
- if Object:IsA("MeshPart") or Object:IsA("UnionOperation") or Object:IsA("BasePart") or Object:IsA("Part") then
- Object.CFrame = ObjectToHighlight:FindFirstChild(Object.Name).CFrame
- end
- end
- ObjectClone.Parent = script.Parent
- ContentProvider:PreloadAsync({ObjectClone})
- for _,Object in pairs (ObjectToHighlight:GetDescendants()) do
- if Object:IsA("MeshPart") then
- Object.TextureID = ""
- Object.Color = HighlightColors[Class] or DefaultHighlightColor
- Object.Material = Enum.Material.Neon
- elseif Object:IsA("UnionOperation") then
- Object.UsePartColor = true
- Object.Color = HighlightColors[Class] or DefaultHighlightColor
- Object.Material = Enum.Material.Neon
- elseif Object:IsA("BasePart") or Object:IsA("Part") then
- Object.Color = HighlightColors[Class] or DefaultHighlightColor
- Object.Material = Enum.Material.Neon
- end
- end
- Connection = RunService.RenderStepped:Connect(function()
- if ObjectToHighlight and ObjectClone then
- for _,Object in pairs (ObjectClone:GetDescendants()) do
- if Object:IsA("MeshPart") or Object:IsA("UnionOperation") or Object:IsA("BasePart") or Object:IsA("Part") then
- Object.CFrame = ObjectToHighlight:FindFirstChild(Object.Name).CFrame
- end
- end
- else
- Connection:Disconnect()
- end
- end)
- end
- local function SetTarget(Target, Class)
- if ObjectToHighlight and ObjectToHighlight ~= Target then
- UnsetTarget()
- elseif ObjectToHighlight and ObjectToHighlight == Target then
- return
- end
- ObjectToHighlight = Target
- if ObjectToHighlight:IsA("MeshPart") and ObjectToHighlight.Texture then
- ObjectProperties["Texture"] = ObjectToHighlight.TextureID
- elseif ObjectToHighlight:IsA("UnionOperation") then
- ObjectProperties["UsePartColor"] = ObjectToHighlight.UsePartColor
- end
- ObjectProperties["Color"] = ObjectToHighlight.Color
- ObjectProperties["Material"] = ObjectToHighlight.Material
- ObjectClone = ObjectToHighlight:Clone()
- print("Target and Clone set")
- ObjectClone.Anchored = true
- ObjectClone.CFrame = ObjectToHighlight.CFrame
- ObjectClone.Parent = script.Parent
- ContentProvider:PreloadAsync({ObjectClone})
- if Class and HighlightColors[Class] then
- ObjectToHighlight.Color = HighlightColors[Class]
- else
- ObjectToHighlight.Color = DefaultHighlightColor
- end
- if ObjectToHighlight:IsA("MeshPart") then
- ObjectToHighlight.TextureID = ""
- elseif ObjectToHighlight:IsA("UnionOperation") then
- ObjectToHighlight.UsePartColor = true
- end
- ObjectToHighlight.Material = Enum.Material.Neon
- UpdateCFrame = RunService.RenderStepped:Connect(function()
- if ObjectToHighlight and ObjectClone then
- ObjectClone.CFrame = ObjectToHighlight.CFrame
- else
- UpdateCFrame:Disconnect()
- end
- end)
- end
- while true do
- if Mouse.Target and Mouse.Target.Name == "TestPart" then
- if Mouse.Target.Parent:IsA("Model") then
- SetModelAsTarget(Mouse.Target.Parent)
- else
- SetTarget(Mouse.Target)
- end
- else
- UnsetTarget()
- end
- wait()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement