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)