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.
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.
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)
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)
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.
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
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)
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.
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?