So for the past month or so I’ve been trying to make a system that is like rust’s building system and so far I’ve had no luck at all. the placement system works but the snapping system just doesn’t want to work.
So right now I’ve seen these posts and tried their suggestions but it isn’t working…
see this is one of them : Placement System Using Attachments Creates Multiple Walls
so the problem with that one is that the walls are on a constant 45 degree that I cant fix
local RS = game:WaitForChild("ReplicatedStorage")
local ClickEvent = RS.PlacementSystem:WaitForChild("ClickToPlace")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local ToolEquiped = false
local Tool = script.Parent
Tool.Equipped:Connect(function()
ToolEquiped = true
Main()
end)
function Main()
while ToolEquiped == true do
wait(0.1)
local WallPos
local MouseTarget = mouse.Target
local target
if MouseTarget then
target = MouseTarget.name
end
if target == "Foundation-Floor" then
local ClosestDistance = math.huge
local ClosestAttachment
for _,attachment in pairs(mouse.Target:GetChildren()) do
if attachment.Name == "WallSnapAttachment" then
local mousePos = mouse.Hit.p
local worldPos = attachment.WorldPosition
local distance = (mousePos - worldPos).Magnitude
if distance < ClosestDistance then
ClosestDistance = distance
ClosestAttachment = attachment
end
end
end
local floor = mouse.Target
local wall = game.Workspace.FakeWall
wall.Transparency = 0.75
local wallCframe = floor.CFrame *CFrame.new(ClosestAttachment.Position)
wallCframe = wallCframe *CFrame.new(-wall.FloorAttachment.Position)
wallCframe = wallCframe *CFrame.Angles(0, math.rad(ClosestAttachment.Orientation.Y), 0)
wall.CFrame = wallCframe
WallPos = wall.Position
else
local wall = game.Workspace.FakeWall
wall.Transparency = 1
end
Tool.Unequipped:Connect(function()
ToolEquiped = false
local wall = game.Workspace.FakeWall
wall.Transparency = 1
end)
local enabled = true
mouse.Button1Down:Connect(function()
if not enabled then return end
enabled = false
ClickEvent:FireServer(WallPos)
wait(0.1)
enabled = true
end)
end
end
-- thats the code i tried with another code in the serverscriptservice
if you can link me to some other toutorial or help me figure it out it would be much appreciated…