|
| 09 Jul 2017 11:57 AM |
I tried for a while to get this script to create a selection box around the player mouse's target if it was a specific brick, then delete that selection box when the mouse target is no longer that specific brick. It creates the selection box, but it doesn't delete the selection box when the target changes:
local mouse = game.Players.LocalPlayer:GetMouse() box = nil game:GetService("RunService").RenderStepped:connect(function() local target = mouse.Target if target then if target.Name == "ClickPart" then if not target:FindFirstChild("Selection") then local selection = Instance.new("SelectionBox") selection.Color3 = Color3.new(0, 0, 255) selection.LineThi ckness = 0.15 --space was added due to filter selection.SurfaceTransparency = 1 selection.Name = "Selection" selection.Adornee = mouse.Target selection.Parent = mouse.Target end else if box then box:Destroy() end end end end) |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2017 12:54 PM |
| You can completely ignore the first few conditional statements, I just need help deleting the selection box when the mouse's target changes. |
|
|
| Report Abuse |
|
|
| |
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 09 Jul 2017 05:09 PM |
| Why don't you do the event of mouse.Move and mouse.Leave, and if it leaves an object, then it deletes the selection box. |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2017 06:49 PM |
Sorry, I wasn't sure one existed because I thought there were only GUI events like that.
Thanks, I'll look it up. |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 09 Jul 2017 06:57 PM |
GuiObjects would have:
MouseEnter
MouseLeave
You would use:
http://wiki.roblox.com/index.php?title=API:Class/Mouse/Move
and possibly:
http://wiki.roblox.com/index.php?title=API:Class/Mouse/Idle |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 09 Jul 2017 06:58 PM |
| I accidentally put mouse.Leave instead of mouse.Idle originally, my bad. |
|
|
| Report Abuse |
|
|
|
| 10 Jul 2017 02:03 PM |
| Oh, that makes sense now. Thanks. |
|
|
| Report Abuse |
|
|
|
| 11 Jul 2017 06:30 PM |
| I can't seem to get it to work. Could someone explain the flaw in the original coding? |
|
|
| Report Abuse |
|
|
|
| 11 Jul 2017 07:20 PM |
Nevermind, I just created a 'for' loop to delete every SelectionBox inside all the ClickParts as a substitute for the end:
function DeleteSelections() local Buildings = game.Workspace:GetChildren() for i = 1, #Buildings do if Buildings[i]:IsA("Model") then local ClickPart = Buildings[i]:FindFirstChild("ClickPart") if ClickPart then local Selection = ClickPart:FindFirstChild("Selection") if Selection then Selection:Destroy() end end end end end |
|
|
| Report Abuse |
|
|