I'm trying to make a SelectionBox and a GUI to appear once I put my Mouse on that part. I got that part over with, but I'm stumped when it comes to removing the SelectionBox and the GUI once the mouse is not detecting that part anymore. I've already tried a method but since there will be a lot of parts around the map it doesn't work correctly.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Previous = ""
Mouse.Move:connect(function()
if Mouse.Target.Name == "Plant" then
local hitbox = Instance.new("SelectionBox", Mouse.Target)
hitbox.LineThickness = 0.05
hitbox.Adornee = Mouse.Target
Player.PlayerGui.ScreenGui.Frame.Visible = true
Player.PlayerGui.ScreenGui.Frame.TextLabel.Text = Mouse.Target.Hits.Value .. "/ 3"
Previous = Mouse.Target.Name
else
workspace[Previous].SelectionBox:remove()
Player.PlayerGui.ScreenGui.Frame.Visible = false
end
end)
It's located in a LocalScript in StarterGui

2 comments
i think you can set the value as the object instead of the name
I tried that, didn't work :c