SelectionBox Issue

So I been working on the delete system for my Placement System and I can’t seem to find the problem to this error. I searched everywhere, DevForum, Youtube and still cant find whats i’m doing wrong. I debugged every part to see if everything functional and again saw no problems with how i set everything up.

Here’s the issue
When the camera is facing forwards ( I see the back of the character ), the delete function work. It highlights the block selected and when i click it deletes the block selected. But when i turn the camera around ( I see in front of the character ), Its glitching out where the adornee is switching between nil and the block even when i’m only hovered over one block.

Here’s the 2 Codes that plays a big part in the Selection/Delete System


function GetModelPart(Obj)
    local Base = nil
    for _, Child in pairs(workspace.Bases:GetChildren()) do
        if Child.Owner.Value == Player then
            Base = Child
        end
    end
    local ToReturn = nil
    if Obj.Parent == Base.Structure then
        ToReturn = Obj
    elseif Obj.Parent == game or Obj.Parent == workspace or Obj.Parent == nil then
        ToReturn = nil
    else
        ToReturn = GetModelPart(Obj.Parent)
    end
    return ToReturn
end
----------------------------------------------------------
Mouse.Move:Connect(function()
        if deleteactive then
            Selection = nil
            if Mouse.Target then
                local Model = GetModelPart(Mouse.Target)
                if Model then
                    Selection = Model
                end
            end
            if Selection then
                SelectionBox.Adornee = Selection.EditPart
            elseif Selection == nil then
                SelectionBox.Adornee = nil
            end    
        end
    end)

Im sorry if my grammar confuses you, If you need me to explain more please tell me.

1 Like

I need a little more information. On what path do you have “Edit Part”?

1 Like

EditPart is the primary part of a model that gets selected by a system, So lets say I placed down a block, its shows 2 parts in the model, one part is the block and the other part is the editpart. It also shows the outside barrier. Another example is lets say I made a door, In the model its gonna have alot of parts for the door but that one part called EditPart is what the system select to get the whole model.

I also use it to have a main size of the item.

This is the code I used to create the selection box using editpart.

        SelectionBox = Instance.new("SelectionBox")
	SelectionBox.Color3 = Color3.fromRGB(241, 16, 0)
	SelectionBox.SurfaceColor3 = Color3.fromRGB(202, 11, 0)
	SelectionBox.SurfaceTransparency = 0.7
	SelectionBox.LineThickness = 0.01
	SelectionBox.Parent = Player.PlayerGui
  • before this, the selectionbox is equal to nil, but once you pressed the button to activate the delete system it create the selectionbox *
1 Like
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

SelectionBox = Instance.new("SelectionBox")
SelectionBox.Color3 = Color3.fromRGB(241, 16, 0)
SelectionBox.SurfaceColor3 = Color3.fromRGB(202, 11, 0)
SelectionBox.SurfaceTransparency = 0.7
SelectionBox.LineThickness = 0.01
SelectionBox.Parent = Player.PlayerGui

Mouse.Move:Connect(function()
	local target = Mouse.Target
	if target then
		if target:IsA("BasePart") and target.Name == "EditPart" then
			SelectionBox.Adornee = target
		else
			SelectionBox.Adornee = nil
		end
	end
end)
1 Like

Here’s the whole function to make things easier to understand.

function GetModelPart(Obj)

	local Base = nil

	for _, Child in pairs(workspace.Bases:GetChildren()) do

		if Child.Owner.Value == Player then

			Base = Child

		end

	end

	local ToReturn = nil

	if Obj.Parent == Base.Structure then

		ToReturn = Obj

	elseif Obj.Parent == game or Obj.Parent == workspace or Obj.Parent == nil then

		ToReturn = nil

	else

		ToReturn = GetModelPart(Obj.Parent)

	end

	return ToReturn
	
end

local deleteactive = false

local SelectionBox = nil
local Selection = nil

deleteButton.MouseButton1Click:Connect(function()

	deleteactive = true

	ui.ButtonFrame.Visible = false
	ui.ExtraButtonsFrame.Visible = true
	ui.ExtraButtonsFrame.DeleteBackButton.Visible = true

	SelectionBox = Instance.new("SelectionBox")
	SelectionBox.Color3 = Color3.fromRGB(241, 16, 0)
	SelectionBox.SurfaceColor3 = Color3.fromRGB(202, 11, 0)
	SelectionBox.SurfaceTransparency = 0.7
	SelectionBox.LineThickness = 0.01
	SelectionBox.Parent = Player.PlayerGui

	Mouse.Move:Connect(function()
		
		if deleteactive then
			
			Selection = nil

			if Mouse.Target then

				local Model = GetModelPart(Mouse.Target)
				
				if Model then

					Selection = Model

				end

			end

			if Selection then
				
				SelectionBox.Adornee = Selection.EditPart

			elseif Selection == nil then
				
				SelectionBox.Adornee = nil
				
			end
			
		end
		
	end)


	Mouse.Button1Down:Connect(function()
		
		if deleteactive then

			Selection = nil

			if Mouse.Target then
			
				local Model = GetModelPart(Mouse.Target)

				if Model then

					Selection = Model

				end

			end

			if Selection then

				game.ReplicatedStorage.Remotes.DeletePart:FireServer(Selection)

			end

				SelectionBox.Adornee = nil

		end
		
	end)

	ui.ExtraButtonsFrame.DeleteBackButton.MouseButton1Click:Connect(function()

		deleteactive = false

		if SelectionBox then

			SelectionBox:Remove()

			SelectionBox = nil

		end

		ui.ExtraButtonsFrame.DeleteBackButton.Visible = false
		ui.ExtraButtonsFrame.Visible = false
		ui.ButtonFrame.Visible = true

	end)
end)
2 Likes

Fine. I understand what you want to achieve. Give me some time to solve this problem!

1 Like

Create an “IntValue” or whatever, you need to store the “deleteactivate” value there. Place the function with the “Move” event separate from the function with the “MouseButton1Click” event.

I can’t say for sure if it will work or not.
You showed me the function, but it’s not the whole code, so it’s a bit complicated.

1 Like

Oh it is separate, Ok how the function works, When the delete system is activated, it create a selectionbox, then there is a function that locates the object edit part. When the mouse moves it runs that function to find the edit part the mouse is selected to. Then when you left click it activates another function that removes the whole part.

the delectactivate boolean is so when I click back to go to the menu it won’t continue running the delete system cause that was already another problem

2 Likes

Show me all your frames on the screen, just make them all visible.

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local ui = Player.PlayerGui:WaitForChild("EditGui")
local deleteButton = ui.ButtonFrame.Delete

function GetModelPart(Obj)

	local Base = nil

	for _, Child in pairs(workspace.Bases:GetChildren()) do

		if Child.Owner.Value == Player then

			Base = Child

		end

	end

	local ToReturn = nil

	if Obj.Parent == Base.Structure then

		ToReturn = Obj

	elseif Obj.Parent == game or Obj.Parent == workspace or Obj.Parent == nil then

		ToReturn = nil

	else

		ToReturn = GetModelPart(Obj.Parent)

	end

	return ToReturn
	
end

local deleteactive = false

local SelectionBox = nil
local Selection = nil

deleteButton.MouseButton1Click:Connect(function()

	deleteactive = true

	ui.ButtonFrame.Visible = false
	ui.ExtraButtonsFrame.Visible = true
	ui.ExtraButtonsFrame.DeleteBackButton.Visible = true

	SelectionBox = Instance.new("SelectionBox")
	SelectionBox.Color3 = Color3.fromRGB(241, 16, 0)
	SelectionBox.SurfaceColor3 = Color3.fromRGB(202, 11, 0)
	SelectionBox.SurfaceTransparency = 0.7
	SelectionBox.LineThickness = 0.01
	SelectionBox.Parent = Player.PlayerGui

	Mouse.Move:Connect(function()
		
		if deleteactive then
			
			Selection = nil

			if Mouse.Target then

				local Model = GetModelPart(Mouse.Target)
				
				if Model then

					Selection = Model

				end

			end

			if Selection then
				
				SelectionBox.Adornee = Selection.EditPart

			elseif Selection == nil then
				
				SelectionBox.Adornee = nil
				
			end
			
		end
		
	end)


	Mouse.Button1Down:Connect(function()
		
		if deleteactive then

			Selection = nil

			if Mouse.Target then
			
				local Model = GetModelPart(Mouse.Target)

				if Model then

					Selection = Model

				end

			end

			if Selection then

				game.ReplicatedStorage.Remotes.DeletePart:FireServer(Selection)

			end

				SelectionBox.Adornee = nil

		end
		
	end)

	ui.ExtraButtonsFrame.DeleteBackButton.MouseButton1Click:Connect(function()

		deleteactive = false

		if SelectionBox then

			SelectionBox:Remove()

			SelectionBox = nil

		end

		ui.ExtraButtonsFrame.DeleteBackButton.Visible = false
		ui.ExtraButtonsFrame.Visible = false
		ui.ButtonFrame.Visible = true

	end)
end)
1 Like

Most likely you are hindered by GUI. Try moving the whole gui up and check again.

1 Like

I have a question, What if its not the gui, everything works when your facing forwards but when I turn the camera around that’s when im having this glitching problem, there’s no errors and everything works.

It might be just the function GetModelPart but I dont see a problem with it.

2 Likes

To help locate the problem, try printing “print()” in each function.

2 Likes

Trust that was the first thing I did before I posted this :smiling_face_with_tear:

1 Like

Is this exactly what happens only when you look at the player? For example, from the side or from the top view does this not happen?

1 Like

Yes, Do you think its a Roblox Issue?

1 Like

I can’t say anything about it. Maybe it’s because of the cursor coordinates.

1 Like

Or it could happen when you hover over some other “part”.

1 Like

It’s whenever I turn the camera around, it gets the part but then it starts glitching out. There’s no error and I debugged everything and everything works, When the camera is facing straight there’s no issue and it works fine.

How can I get a Roblox admin to look at this to see if it is a Roblox issue?

2 Likes

Perhaps there are admin accounts that can be mentioned.

1 Like