Toggle properties

Im trying to make a part get a highligt when i hover over it and press f. If it already has a highlight it turns it off, but if it does not have an highlight it turns on.

localscript:

local repliatedstorage = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
repliatedstorage.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.F then
local object = player:GetMouse().Target
local high = Instance.new("Highlight",object)
high.FillColor = Color3.fromRGB(38, 114, 255)
high.OutlineColor = Color3.fromRGB(255, 0, 0)
if object.HighLight.Enabled = true then
object.HighLight.Enabled = false
local object = 0
if object.HighLight.Enabled = false then
object.HighLight.Enabled = true
end end end end end)

You need to set the Adornee of the highlight to the object that you want to highlight as well

1 Like

Try to format your code but I think you want something like this:

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard or input.KeyCode == Enum.KeyCode.F then
		local object = player:GetMouse().Target
		local high = object.FindFirstChildOfClass("Highlight")
		
		if not high then
			high = Instance.new("Highlight",object)
			high.FillColor = Color3.fromRGB(38, 114, 255)
			high.OutlineColor = Color3.fromRGB(255, 0, 0)
		end
		
		
		high.Enabled = not high.Enabled
	end 
end)
1 Like

What’s an adornee? Im new to lua so i dont know too many words.

You can see all properties:

Adornee must be egal to an Instance.

Highlight.Adornee = myPart
1 Like

An adornee is the property of the Highlight that controls what the highlight is actually highlighting.
For example

highlight.Adornee = myPart1

makes the highlight do its job and actually highlight myPart1

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.