I have made a script that creates a Selectionbox into a part if the mouse is hovering over that part. the problem is I don’t know how to detect if the mouse has stopped hovering over the part, so I can disable the Selectionbox. Any Ideas?
Here is what it’s supposed to look like:
and here is what is happening:
local mouse = player:GetMouse()
local tool = script.Parent
tool.Equipped:Connect(function()
mouse.Move:Connect(function(target)
if mouse.Target.Name == "wallsegment" then
local selectionbox = Instance.new("SelectionBox")
selectionbox.Adornee = mouse.Target
selectionbox.Color3 = Color3.fromRGB(18,230,3)
selectionbox.Visible = true
selectionbox.LineThickness = .01
selectionbox.Parent = mouse.Target
end
end)
end)
1 Like
how would I Make a Variable for that?
You could have it so that it uses just one SelectionBox
, then when the player’s mouse hovered over the part, it sets the SelectionBox’s Adornee
to the part.
Making some edits to your script to reflect this:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local selectionbox = Instance.new("SelectionBox")
selectionbox.Color3 = Color3.fromRGB(18,230,3)
selectionbox.Visible = true
selectionbox.LineThickness = .01
selectionbox.Parent = player.PlayerGui
tool.Equipped:Connect(function()
mouse.Move:Connect(function(target)
if mouse.Target.Name == "wallsegment" then
selectionbox.Adornee = mouse.Target
else
selectionbox.Adornee = nil
end
end)
end)
I hope this helped. 
1 Like
Thank you this is the solution 
1 Like