I want to make an effect that when you click a part, a new part that is cut out from the original part is made.
For example:
gyazo link of what I am trying to do
local cd = script.Parent.ClickDetector local part = script.Parent local v3 = Vector3 function divide(brick, mousepos) local maxSize = brick.Size - v3.new(2,2,2) local newPart = brick:Clone() newPart.Size = v3.new(math.random(1, maxSize.X),math.random(1, maxSize.Y),math.random(1, maxSize.Z)) newPart.CFrame = CFrame.new(mousepos) newPart.CanCollide = false newPart.Anchored = false newPart.Parent = workspace newPart.ClickDetector:Destroy() local bv = Instance.new("BodyVelocity") bv.MaxForce = v3.new(1,1,1) * math.huge bv.Velocity = newPart.CFrame.lookVector * -1.1 bv.Parent = newPart end cd.MouseClick:Connect(function(player) local mouse = player:GetMouse() divide(part, mouse.Hit.p) end)
Edit: I removed the click detector and detected clicking from a local script but I still need help with the concept of cutting the part.
This is the code I have. I randomize a section of the original part (called brick in the function), then I make a clone of the original part and place it where the player clicked then I instanced body velocity so I can see the new parts. I still need to cut out the sections from the original part.
Thanks for reading and any help will be greatly appreciated.
The following is an example, of creating two identical half size parts, that will appear to have been cut from the original part (the original part gets destroyed). You’ll have to play around with the position and axis, you cant cut multiple axis (to my knowledge). This example cuts the X axis. Hope it’s helpful. As incapaz said, the server can’t getMouse, that’s a client side function.
function CutPart(orig) --Gather the extents of the new parts --Cut the x axis local extentsX,extentsZ,extentsY = orig.Size.X/2,orig.Size.Y,orig.Size.Z; --Define the origin local pos = orig.CFrame; for i = 1,2 do --For loop for 2 parts local new = orig:Clone(); --Clone and cut new.Size = Vector3.new(extentsX,extentsY,extentsZ); --Account position for each side of the axis you're cutting --Divide in half again to get 1/4th size local x = (i == 1 and -extentsX/2) or extentsX/2; --Move in from the origin local newPos = pos * CFrame.new(x,0,0); new.CFrame = newPos; new.Parent = orig.Parent; end orig:Destroy(); --Destroy the original part end
Then call this function in a part...
local p = Instance.new("Part",workspace); p.Size = Vector3.new(5,5,5); p.CFrame = CFrame.new(0,10,0); p.Anchored = true; wait(2); CutPart(p