-
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.
-
What is the issue? https://gyazo.com/6dd1ab6d035d6e1f74382be86d0dbdc2
-
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)