Attachment Building Issue

  1. What do you want to achieve? I want to achieve where if the player already placed the wall and snapped to the attachment how would I prevent the player from placing another wall in the same place.

  2. What is the issue? https://gyazo.com/6dd1ab6d035d6e1f74382be86d0dbdc2

  3. What solutions have you tried so far? I been asking people in the Roblox Discord Server but everyone seems to say tables and attributes, if I gave them an example of deleting a part and setting the attribute value back to false, they just say, “I don’t know”. But, if I used tables and tried to check if the attachment is already used, how would I use in another script when deleting the part?

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse()

local function UnitRay()
	local ur = Mouse.UnitRay
	return ur.Origin, ur.Direction * 10000
end

local Wall = ReplicatedStorage:WaitForChild("Wall")

local ClonedSample = Wall:Clone()
ClonedSample.Parent = workspace
ClonedSample.Material = Enum.Material.Neon
ClonedSample.CanCollide = false
ClonedSample.Anchored = true

local GoodToPlace = false
local Attachment = nil

RunService.RenderStepped:Connect(function()

	local Origin, Direction = UnitRay()
	local Params = RaycastParams.new()

	Params.FilterType = Enum.RaycastFilterType.Blacklist
	Params.FilterDescendantsInstances = {Character, ClonedSample}

	local Raycast = workspace:Raycast(Origin, Direction, Params)

	if Raycast and Raycast.Instance then
		local RaycastInstance = Raycast.Instance
		local nearestAttachment = nil

		for i, attachment in pairs(RaycastInstance:GetChildren()) do
			if attachment:IsA("Attachment") then
				if attachment.Name == "WallAttachment" then
					local attachmentPosition = attachment.WorldPosition
					local RaycastPosition = Raycast.Position

					if (RaycastPosition - attachmentPosition).Magnitude < 2 then
						nearestAttachment = attachment
						Attachment = attachment

						local wallCframe = RaycastInstance.CFrame *CFrame.new(attachment.Position)
						wallCframe = wallCframe *CFrame.new(-ClonedSample.FloorAttachment.Position)
						wallCframe = wallCframe *CFrame.Angles(0, math.rad(attachment.Orientation.Y), 0)
						ClonedSample.CFrame = wallCframe

						if GoodToPlace ~= nil then
							GoodToPlace = true
							ClonedSample.Color = Color3.fromRGB(0, 255, 0)
						end
					end
				end
			end

			if nearestAttachment == nil and GoodToPlace ~= nil then
				ClonedSample.CFrame = CFrame.new(Raycast.Position.X, Raycast.Position.Y + ClonedSample.Size.Y/2, Raycast.Position.Z)
				GoodToPlace = false
				ClonedSample.Color = Color3.fromRGB(255, 0, 0)
			end
		end
	end
end)

UserInputService.InputBegan:Connect(function(Input, gameProcessedEvent)
	if gameProcessedEvent then return end

	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		if GoodToPlace then
			if Attachment ~= nil then
				ReplicatedStorage:WaitForChild("CallPlace"):InvokeServer(ClonedSample.Name, ClonedSample.CFrame)
			end
		end
	end
end)

Add a attachment ignore list.
This ignore list will have attachments that can not have any objects placed on them.

When you put a wall on the attachment, Add the attachment to the ignore list.

If the wall was removed. You can remove the attachment from the ignore list.

The ignore list can be an array or a dictionary that contains what each attachment’s used object ({Attachment = wall} With that you can make a pairs loop to find what attachment is connected to that wall and remove the attachment from the ignore list by doing IgnoreList[Attachment] = nil.

If you are using a array you can use
table.remove(IgnoreList, table.find(IgnoreList, Attachment)

When trying to place a new wall you can use table.find(IgnoreList, Attachment) to see if the attachment is in the ignore list, if so then you can’t place an wall there.

If your not using an array you can use a loop to find out.

I’m currently using ObjectValues

I fixed it using ObjectValues and attributes :confused: