Part placing system has weird behavior

Hello everyone, I am trying to create an part placing system, which will allow player to place blocks from he’s or she’s inventory. My script is not allowing player to place parts smoothly and it’s glitchy during usage. In my video below it’s my current placing system.

In video below it’s the part placing system I am trying to achieve

I know I may not doing an right thing, but I am trying to achieve this, does anyone has any idea how I could achieve this?

if Can == true then
	if game.Players[Player.Name].leaderstats[Currency].Value >= Price then
		game.Players[Player.Name].leaderstats[Currency].Value = game.Players[Player.Name].leaderstats[Currency].Value - Price
		Unit = Unit:Clone()
		Unit.Parent = game.Workspace
		if Unit:IsA("Model") then
			if Unit:FindFirstChild("Humanoid") then
				
			else
				for i, v in pairs(Unit:GetChildren()) do
					if v:IsA("Part") or v:IsA("MeshPart") then
						v.Anchored = true
					end
				end
			end
		else
			Unit.Anchored = true
		end
		if Unit:IsA("Model") then
			if Unit:FindFirstChild("Humanoid") then
				
			else
				for i, v in pairs(Unit:GetChildren()) do
					if v:IsA("Part") or v:IsA("MeshPart") then
						v.Transparency = 0
					end
				end
			end
		else
			Unit.Transparency = 0
		end
		if Unit:IsA("Model") then
			for i, v in pairs(Unit:GetChildren()) do
				if v:IsA("Part") or v:IsA("MeshPart") then
					v.CanCollide = true
				end
			end
		else
			Unit.CanCollide = true
		end
		if Unit:IsA("Model") then
			-- Cannot rotate group
		else
			Unit.Orientation = Rotation
		end
		if Unit:IsA("Model") then
			Unit:SetPrimaryPartCFrame(CFrame.new(Hit.Position))
			Unit:SetPrimaryPartCFrame(CFrame.new(Unit.PrimaryPart.Position.X + Unit.PrimaryPart.Size.X / 2, Unit.PrimaryPart.Position.Y + Unit.PrimaryPart.Size.Y / 2, Unit.PrimaryPart.Position.Z + Unit.PrimaryPart.Size.Z / 2))
		else
			Unit.Position = Hit.Position
			Unit.Position = Vector3.new(Unit.Position.X + Unit.Size.X / 2, Unit.Position.Y + Unit.Size.Y / 2, Unit.Position.Z + Unit.Size.Z / 2)
		end
	    if Unit:FindFirstChild("ClickDetector") then
			Unit.ClickDetector.MaxActivationDistance = 10
		end
		if Unit:FindFirstChild("Team") then
			Unit.Team.Value = game.Players[Player.Name].Team.Name
		end
		if Unit:IsA("Model") then
			Unit[Unit.PrimaryPart.Name].PlaceSound:Play()
		else
			Unit.PlaceSound:Play()
		end
	else
		game.ReplicatedStorage.GameNotification:FireAllClients(Player, "Unit Editor", "Not enough ".. Currency.. " to place this item")
	end
else
	game.ReplicatedStorage.GameNotification:FireAllClients(Player, "Unit Editor", "You tried place this item too far away from you")
end

This is my script that does place part. So if you have any idea how to achieve the part placing system like in someones tweet please tell me. Thank you!

I’ve cleaned your code up for the sake of it being easier to read;

if Can == true then
  if game.Players[Player.Name].leaderstats[Currency].Value >= Price then
    game.Players[Player.Name].leaderstats[Currency].Value = game.Players[Player.Name].leaderstats[Currency].Value - Price
    Unit = Unit:Clone()
    Unit.Parent = game.Workspace
    if Unit:IsA("Model") then
      if Unit:FindFirstChild("Humanoid") then

      else
        for i, v in pairs(Unit:GetChildren()) do
          if v:IsA("Part") or v:IsA("MeshPart") then
            v.Anchored = true
          end
        end
      end
    else
      Unit.Anchored = true
    end
    if Unit:IsA("Model") then
      if Unit:FindFirstChild("Humanoid") then

      else
        for i, v in pairs(Unit:GetChildren()) do
          if v:IsA("Part") or v:IsA("MeshPart") then
            v.Transparency = 0
          end
        end
      end
    else
      Unit.Transparency = 0
    end
    if Unit:IsA("Model") then
      for i, v in pairs(Unit:GetChildren()) do
        if v:IsA("Part") or v:IsA("MeshPart") then
          v.CanCollide = true
        end
      end
    else
      Unit.CanCollide = true
    end
    if Unit:IsA("Model") then
      -- Cannot rotate group
    else
      Unit.Orientation = Rotation
    end
    if Unit:IsA("Model") then
      Unit:SetPrimaryPartCFrame(CFrame.new(Hit.Position))
      Unit:SetPrimaryPartCFrame(CFrame.new(Unit.PrimaryPart.Position.X + Unit.PrimaryPart.Size.X / 2, Unit.PrimaryPart.Position.Y + Unit.PrimaryPart.Size.Y / 2, Unit.PrimaryPart.Position.Z + Unit.PrimaryPart.Size.Z / 2))
    else
      Unit.Position = Hit.Position
      Unit.Position = Vector3.new(Unit.Position.X + Unit.Size.X / 2, Unit.Position.Y + Unit.Size.Y / 2, Unit.Position.Z + Unit.Size.Z / 2)
    end
    if Unit:FindFirstChild("ClickDetector") then
      Unit.ClickDetector.MaxActivationDistance = 10
    end
    if Unit:FindFirstChild("Team") then
      Unit.Team.Value = game.Players[Player.Name].Team.Name
    end
    if Unit:IsA("Model") then
      Unit[Unit.PrimaryPart.Name].PlaceSound:Play()
    else
      Unit.PlaceSound:Play()
    end
  else
    game.ReplicatedStorage.GameNotification:FireAllClients(Player, "Unit Editor", "Not enough ".. Currency.. " to place this item")
  end
else
  game.ReplicatedStorage.GameNotification:FireAllClients(Player, "Unit Editor", "You tried place this item too far away from you")
end

Could you explain more in depth what the issue is? You are only telling us it’s not placing smoothly, have you debugged yet?

I am trying to achieve block/part placing system like in the someones tweet: x.com

Yes, and I did debugging part

Over the past 6 or so months I’ve seen many, many part placement topics. A couple of them discussed collisions, which is part of what you are looking for.

There is such demand for placement systems and so many developers have issues with them that I think it would be profitable to implement a single well done and highly customizable placement system…

1 Like

I am beginner in mouse and ray casting stuff. I had a lot of issues during my part placing system development

I noticed your placement is just the part following the mouse position and then when you Button1Down it clones that part and puts it in the position of where the mouse was, I’ve made many nice placement systems, but I recommend you do not start of with a placement system. I recommend you go and look for open source systems, and look at how they are made, and then making your own. That tweet does not look like a simple system, I can tell you it’s a lot more advanced than you think.

Edit; I recommend checking out EggoMoose’s open source placement, this will help you I think, I recommend deconstructing it, checking how its made, and then you make your own version of it! The only issue is, you’d need to make your own grid system to be able to place a part on another part without it being all weird and not smooth. Here is the game link;

EggoMoose’s open source Placement

1 Like

Yes, it is really advanced, comparing to mine. Is anyone has idea how to make better collision during placing parts?

1 Like

Ah, she is a very well respected developer in the Roblox office and a contributor to Roact as well. She used a critically dampened spring with a specific grid size. It is a little extra complexity on top of a working system.

During watching video, I notice that the blocks are placed in the grid, comparing to mine.

She made a special tween for when the part is placed or moving, she also made a special grid. Like I suggested, check out eggomoose’s system, deconstruct it, customize it, and then learn how to make a grid so you can place parts without them looking “weird”.

Is possible to create better collision in my placing system tho?

Unit:SetPrimaryPartCFrame(CFrame.new(Hit.Position))
Unit:SetPrimaryPartCFrame(CFrame.new(Unit.PrimaryPart.Position.X + Unit.PrimaryPart.Size.X / 2,  Unit.PrimaryPart.Position.Y + Unit.PrimaryPart.Size.Y / 2, Unit.PrimaryPart.Position.Z + Unit.PrimaryPart.Size.Z / 2))

I honestly do not recommend what you are doing, there are good open sourced placement systems that you can deconstruct to learn to make your own without having any issues.

Could you send me link to one of open sourced placing systems?

If you scroll up just a tad bit you will see the open sourced placement I provided to you and an explanation;

There is one problem, it does place perfectly but does not allow player to place block on top of another block

I did just say that, and I informed you that you will need to make your own grid system.

Edit;

Making your own placement system smooth, and clean isn’t the easiest. I recommend looking at open sourced placing systems, and then give making your own grid system a shot, in addition to making your own placement. Trust me, it will be really rewarding once you are done learning, and completed it.

1 Like