#Highlight Tool not working (mouse bug)
32 messages · Page 1 of 1 (latest)
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local currentHighlight = nil
local currentTarget = nil
local moveConnection = nil
local function createHighlight(character)
if currentHighlight then
currentHighlight:Destroy()
end
local highlight = Instance.new("Highlight")
highlight.Parent = character
highlight.OutlineColor = Color3.fromRGB(255, 0, 0)
highlight.FillColor = Color3.fromRGB(255, 0, 0)
currentHighlight = highlight
currentTarget = character
end
local function onMouseMove()
local target = mouse.Target
if target then
warn("target: ", target, target.Name, target.Parent)
local targetPlayer = players:GetPlayerFromCharacter(target.Parent)
if targetPlayer and targetPlayer ~= player then
if currentTarget ~= target.Parent then
print("hovering: ", targetPlayer.Name)
createHighlight(target.Parent)
end
else
if currentHighlight then
currentHighlight:Destroy()
currentHighlight = nil
currentTarget = nil
end
end
else
if currentHighlight then
currentHighlight:Destroy()
currentHighlight = nil
currentTarget = nil
end
end
end
tool.Equipped:Connect(function()
warn("tool equipped")
if moveConnection then
moveConnection:Disconnect()
end
moveConnection = mouse.Move:Connect(onMouseMove)
end)
tool.Unequipped:Connect(function()
if currentHighlight then
currentHighlight:Destroy()
currentHighlight = nil
currentTarget = nil
end
if moveConnection then
moveConnection:Disconnect()
moveConnection = nil
end
end)
localscript under tool
tbh, didnt even know mouse.move was a thing - have you tested it works separate to this main script? the mouse.move event that is
i think it's quite old, so there could be issues with it, but the wiki does suggest it may still work
do you know any alternatives to mouse.move
userinputservice
you can do UserInputService.InputChanged and then detect mouse movement
indeedly
it is a little finicky to learn it at the start but you get used to it
cause it has a few odd bits and bobs
so wait would it be something like this
game:GetService("UserInputService").InputChanged:Connect(function(input, proc)
if not proc and input ==
end)
whats the thing to get the mouse
input.Position gives you a Vector3 of the mouse position
damn
but, i suppose you could just use that for the event, and then use the Mouse object for Mouse.Target or whatever you wanna do
maybe its cheesing it a little
alternative is casting a ray from the camera at the mouse position which i always find annoying to set up
hmmmmmmmmmm
ok i think i figured it out
userInputService.InputChanged:Connect(function(input, proc)
input:GetPropertyChangedSignal("Position"):Connect(function()
warn(mouse.Target)
end)
end)
this works im pretty sure
ty for letting me know about the userinputservice way
i dont think it will, input is an object created each time the inputchanged event fires
lmk tho
are you using mouse raycasting?
** You are now Level 4! **
mouse.Hit and userinputservice