local str = Instance.new("StringValue")
local object = player:GetMouse().Target
str.Value = object
str:GetPropertyChangedSignal("Value"):Connect(function()
long (full code)
local str = Instance.new("StringValue")
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local function f()
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)
high.Enabled = not high.Enabled
end
high.Enabled = not high.Enabled
str.Value = object
str:GetPropertyChangedSignal("Value"):Connect(function()
oldobject.HighLight.Enabled = false
end)
end
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.F then
local oldobject = object
oldobject.HighLight.Enabled = false
end
f()
end)
It looks like you’re just wanting to disable the highlight once the target has changed. You can do this by having a global variable for storing the target objects and then checking the new target against it whenever the function is called again.
local player = game.Players.LocalPlayer
local target
local function f()
newTarget = player:GetMouse().Target
local high = newTarget: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)
high.Enabled = not high.Enabled
end
high.Enabled = not high.Enabled
if newTarget ~= target then
target.HighLight.Enabled = false
end
target = newTarget
end
Ive added an F key detector and now the errors are "Players.borisglibusic.PlayerScripts.localselect:20: attempt to index nil with ‘HighLight’
borisglibusic is my username and the localscript is named localselect. The localscript is also inside of starterplayerscripts
code now:
local player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local target
local function f()
newTarget = player:GetMouse().Target
local high = newTarget: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)
high.Enabled = not high.Enabled
end
high.Enabled = not high.Enabled
if newTarget ~= target then
target.HighLight.Enabled = false
end
target = newTarget
end
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.F then
f()
end
end)
local Players = game:GetService('Players')
local UserInputService = game:GetService('UserInputService')
local player = Players.LocalPlayer
local target;
local function f()
local newTarget = player:GetMouse().Target
local high = newTarget:FindFirstChildOfClass("Highlight")
if not high then
high = Instance.new("Highlight", newTarget)
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 target and newTarget ~= target then
target.Highlight.Enabled = false
end
target = newTarget
end
UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.F then
f()
end
end)