I have tried quite a few methods, I am trying to get the area between multiple parts so the item I place down can only be placed n that area, and not on the outside of that area.
Here is an image of the area: pasteboard.co/HVrdQ2a.png
local m = {} -- Priority Variables local uis = game:GetService("UserInputService") local runService = game:GetService("RunService") local rs = game:GetService("ReplicatedStorage") local furniture = rs["Furniture"] local remotes = rs["Remotes"] local confrimPlacement = remotes["ConfirmPlacement"] -- Secondary Variables local studio = workspace:WaitForChild("Harbour Studio") local studioFurniture = studio["Furniture"] local owner = studio["Owner"] --Model Placement Varibles local plr local mouse local itemsFrame local finished local node local preview local pp local selection local canPlace local rot = 0 local placing function previewItem() if (placing == false) then return end local allNodes = studio["Nodes"]:GetChildren() for _,n in next, allNodes do node = n end if (owner.Value == plr.Name) and (pp.Position - node.Size).magnitude < (node.Position - pp.Size).magnitude then selection.Color3 = Color3.fromRGB(0,155,0) canPlace = true else selection.Color3 = Color3.fromRGB(155,0,0) canPlace = false end local angle = CFrame.fromEulerAnglesXYZ(0,math.rad(rot),0) local vec = Vector3.new(0,preview.PrimaryPart.Size.Y/2,0) local cf = CFrame.new(mouse.Hit.p+vec)*angle preview:SetPrimaryPartCFrame(cf) end function m.start(p, modelName, frame, fin) plr = p itemsFrame = frame finished = fin itemsFrame.Visible = false finished.Visible = false mouse = plr:GetMouse() --node = studio["Node1"] preview = furniture[modelName]:Clone() preview.Parent = workspace pp = preview.PrimaryPart selection = Instance.new("SelectionBox", workspace) selection.LineThickness = 0.05 selection.Adornee = pp mouse.TargetFilter = preview for i,p in next, preview:GetChildren() do if not (p.Name == "Hitbox") then p.Transparency = 0.5 p.CanCollide = false end end placing = true runService.RenderStepped:Connect(previewItem) end function m.cancel() if (preview) then placing = false preview:Destroy() selection:Destroy() plr = nil mouse = nil node = nil mag = nil preview = nil pp = nil selection = nil canPlace = nil rot = 0 itemsFrame.Visible = true itemsFrame = nil finished.Visible = true finished = nil end end function m.rotate() if (preview) then rot = rot +1 preview:SetPrimaryPartCFrame(preview.PrimaryPart.CFrame*CFrame.fromEulerAnglesXYZ(0,math.rad(rot),0)) end end function m.place() if (preview) and (placing == true) and (canPlace == true) then placing = false confrimPlacement:FireServer(preview.Name, preview:GetPrimaryPartCFrame()) end end return m
I think you mean magnitude. You can use magnitude to find the distance between two objects. Here's an example:
local Part1 = workspace.Part1 local Part2 = workspace.Part2 local magnitude = (Part.Position - Part2.Position).magnitude
Resources:
Accept and upvote if this helped!
Magnitude is basically the distance between 2 points, in your case it's the distance between your 2 parts. The distance is measured in studs so if you were to do
local Part1 = game.workspace.Part1 local Part2 = game.workspace.Part2 local distance = (Part1.Position - Part2.Position).magnitude -- this finds the distance between the 2 parts wait(3) print("distance")
What printing the distance will do is tell you the exact amount of studs between Part1 and Part2. You can do much more with it rather than just printing such as finding the distance between a part and a player's torso, then if the distance is less than or greater than a certain amount of studs, you can do something.