Support with my building system

I am trying to make a building system for a game. Here’s what I have so far (I’ll make the thing that you hold smaller in the future just not at the moment):

There’s a problem though. Those are supposed to be cubes. Not Slabs. See what happens when I make the baseplate transparent?

There’s also a strange glitch that when you try and place it on a platform that’s higher than you are, it flahses and can’t decide where it wants to go.

I’ve tried adding a 1 or 2 to the y position but then it just does that same glitch on any surface.
By the way, because I hate life and I suck at CFrames, rays etc I just used mouse.hit for this. I couldn’t just use mouse.Hit.Position.Y for this either because then the preview starts moving towards your camera uncontrollably. I’ll include my code below for the server and the client.

Client (Inside the tool)
local mouse = game.Players.LocalPlayer:GetMouse()
local RenderStepFunction = nil
local rs = game:GetService("RunService")
script.Parent.Equipped:Connect(function()
	local preview = script.Parent.Handle:Clone()
	preview.Parent = workspace
	preview.Name = "Preview"
	preview.Transparency = 0.5
	preview.CanCollide = false
	preview.Anchored = true
	RenderStepFunction = rs.RenderStepped:Connect(function()
		if mouse.Target ~= nil and mouse.Target:IsA("BasePart") then
			preview.Position = Vector3.new(math.ceil(mouse.Hit.Position.X), mouse.Target.Position.Y * 2, math.ceil(mouse.Hit.Position.Z))
			preview.Orientation = Vector3.new(0, 0, 0)
		end
	end)
end)
script.Parent.Unequipped:Connect(function()
	pcall(function()
		RenderStepFunction:Disconnect() -- Disconnect the function that makes the preview update
		game.Workspace:FindFirstChild("Preview"):Destroy()	-- Get rid of the preview
	end)
end)
script.Parent.Activated:Connect(function()
	if game.Workspace:FindFirstChild("Preview") then
		game.ReplicatedStorage.PlaceBlock:FireServer(script.Parent.Name, Vector3.new(4, 4, 4), script.Parent.Handle.Color, game.Workspace.Preview.Position, Vector3.new(0, 0, 0), true, true, game.Workspace.Builds[game.Players.LocalPlayer.Name]) -- Tell the server to make the part.
		if script.Parent.Limited.Value == true then
			script.Parent:Destroy()
			game.Workspace.Preview:Destroy()
		end
	end
end)
Server side
game.Players.PlayerAdded:Connect(function(player)

local buildsFolder = Instance.new("Folder", workspace.Builds) -- Create a folder for the player's builds

buildsFolder.Name = player.Name

end)

game.Players.PlayerRemoving:Connect(function(player)

if script.Config.DeleteBuildsOnLeave.Value == true then

game.Workspace:FindFirstChild(player.Name):Destroy() -- Clean up the player's builds when they leave

end

end)

game.ReplicatedStorage.BreakBlock.OnServerEvent:Connect(function(player, part)

part:Destroy()

end)

game.ReplicatedStorage.PlaceBlock.OnServerEvent:Connect(function(player, name, size, color, position, Orientation, canCollide, anchored, parent)

local p = Instance.new("Part", parent)

p.Name = name

p.Size = size

p.Color = color

p.Position = position

p.Orientation = Orientation

p.CanCollide = canCollide

p.Anchored = anchored

p.TopSurface = Enum.SurfaceType.Smooth

p.BottomSurface = Enum.SurfaceType.Smooth

end)

Here’s my theory: The mouse.target is constantly switching between the platform and the baseplate causing it to keep jumping back and forth between the positions.

Any ideas as to why this might be happening?

(Oh and lastly I was wondering how you would make a snap to grid system for more than one stud. I managed to snap it to one stud with math.cecil but I was wondering how to do this with something like four studs.)

And yes I know my code is ugly don’t bully me

Just make it go ontop of whatever its based on by doing simple maths

--[[I don't know how you placed it but you'll have to add]] + Vector3.new(0, cube.Size.Y/2,0)

Basically makes the cube go updwards half its height since its being placed with its middle on the ground causing it to stick into the ground

2 Likes

Here is what I did with my building system:

item.CFrame = CFrame.new(mouse.Hit.X/1.2,item.Size.Y/2 + workspace.Grid.Size.Y,mouse.Hit.Z/1.2)
```

workspace.Grid? Is that something for your game only and is it safe to remove that?

Or is that just a thing I had no idea existed.

1 Like

It’s the plot you can do that with a baseplate (A plot where the player is placing for my game).

Just use workspace.BasePlate instead of grid.

And that line of code is inside Runservice.RenderStepped.

Hmm… there’s still a bit of an offset on the y scale, and it only lets me place on the baseplate (I wanted you to be able to build anywhere) but I’m sure I can find a workaround. Thanks though!

1 Like

Right here if you changed this:

to this:

mouse.TragetFliter = preview
if mouse.Target ~= nil and mouse.Target:IsA("BasePart") then
			preview.Position = Vector3.new(math.ceil(mouse.Hit.Position.X), mouse.Target.Position.Y * 2, math.ceil(mouse.Hit.Position.Z))
			preview.Orientation = Vector3.new(0, 0, 0)
		end

it won’t flicker up and down until the position is updated.

What happens in it detects it’s self and it moves up. Using TargetFilter roblox will ignore that part when using Hit and Target . I know for when i used to study this lol :coefficients: :

2 Likes