Disable old property

Hello. Im trying to make a system that activates a highlight on the object that you hover your mouse on and press f. I can toggle it by pressing f on the object again, but the problem is that if i change the object i press f on the highlight on the old object is still there.

Localscript:

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

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

		high.Enabled = not high.Enabled
		if object.Changed then
			delay(0.5, function()
			local oldobject = object
			end)
			not oldhigh.Enabled
		end
		end
	end)

Didn’t you just make a post like this?

I made a post that was about toggling the property on and off before, now its about disabling the old property

1 Like

you spelled “Highlight” wrong here

Also, looking at the code quickly you should probably be using a table to track what objects you want to get highlighted because right now you’re highlighting literally everything in the game. Try keeping a whitelist of what should be highlighted (player characters excluding your own) and linking a highlight instance to that player to index if they are being hovered over.