Weird bug started happening when I added the Billboardgui system to my game, the previous clicked placements that support billboardgui get picked up when not ordered to. Video is provided for a better explanation.
Video:
Code:
Mouse.Button1Down:Connect(function()
if not Placement_Hologram and Mouse.Target ~= nil then -- if not placing hologram and mouse target is not nil to avoid error
local Clicked_Target = Mouse.Target
local Target_Ancestor = Mouse.Target:FindFirstAncestorOfClass("Model")
-- if clicked target does not have clickdetector and Target_Ancestor is found and has Tag EditablePlacement
if not Clicked_Target:FindFirstChildOfClass("ClickDetector") and Target_Ancestor and Target_Ancestor:HasTag("EditablePlacement") then
if PlayerIn_EditMode then -- If in edit mode and not placing any placements
QuickGuide.Adornee = Clicked_Target
QuickGuide.Enabled = true
QuickGuide.Content.Pickup.MouseButton1Click:Connect(function()
if not DB_2 then DB_2 = true
local Result, ErrorMsg = pcall(function()
PickUpPlacement:FireServer(Target_Ancestor) -- sends mouse target ancestor to "Placement"
end)
if not Result then
warn("Failed To Pick Up", Mouse.Target.Name, "ErrorMsg:", ErrorMsg)
end
DB_2 = false
end
end)
-- ADD delete HERE
else
print("Player Edit Mode Is:", PlayerIn_EditMode)
end
else -- if clicked placement or object has no tag
QuickGuide.Enabled = false -- turns off QuickGuide aka "Pickup & Delete" when player press something that is not a placement
return -- print("No Tag")
end
end
end)
I added the print statment and it seems like the event function runs more than once
PickUpPlacement:
function CallerFor_SaveLoad_Placement(Player:Player, Save:boolean, Placement, cframe)
if not DB then DB = true
if Save then -- if save placement --Tip: "SaveLoad_Tools" is called before saving placement to prevent duplications of placements
local Found_Placement = Placable_Objects:FindFirstChild(Placement):Clone()
--
Manager.SaveLoad_Tools(nil, Placement, nil, true) -- Remove Placement Tool Table
--
Manager.SaveLoad_Placement(nil, Placement, cframe) -- Save Placement To Table First
--
Found_Placement:SetPrimaryPartCFrame(CFrame.new(cframe.Position.X, cframe.Position.Y, cframe.Position.Z) * CFrame.Angles(cframe:ToEulerAnglesXYZ())) -- Sets Position and orientation before parenting to "Placed_Objects"
Found_Placement.Parent = Placed_Objects -- Clones "Found_Placement" and parents it to "Placed_Objects"
else -- if not save then remove
local Found_Tool = PlacementTool:FindFirstChild(Placement.Name) -- Finds Placement Toole
--
Manager.SaveLoad_Placement(nil, Placement.Name, nil, true) -- Removes Placement Table
Placement:Destroy() -- Destroyes The Clicked Placement
--
Manager.SaveLoad_Tools(nil, Found_Tool.Name, nil, nil, true) -- Adds Placement Tool To Table
Found_Tool:Clone().Parent = Player:FindFirstChild("Backpack") -- Clones Placement Tool To Backpack
end
DB = false
end
end
PlacePlacement.OnServerEvent:Connect(function(Player, PlacementName, cframe)
CallerFor_SaveLoad_Placement(Player, true, PlacementName, cframe)
end)
PickUpPlacement.OnServerEvent:Connect(function(Player, Placement)
--print(Placement)
CallerFor_SaveLoad_Placement(Player, false, Placement)
end)
You can see here Target_Ancestor is getting printed more than once