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)
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)