Can anyone give me a suggestion of how to make a Grid Placement Mode for my game?

You can write your topic however you want, but you need to answer these questions:

  1. I want to make a Grid Build System for players to place items on their plot which makes it save for when they come back

  2. I’ve tried a few attempts with it and they don’t really work the way I would like them to. They either don’t move in a Grid Formation or keep their orientation aligned with the orientation of the plot. i really need someone to tell me what resources to use or how to RayCast.

  3. Here’s my attempt at the system:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Camera = game.Workspace.CurrentCamera

local BuildPro = false
local OnPlot = false

local BuildUi = script.Parent.FHOS.Frame.BuildFrame

local MarketPlaceService = game:GetService("MarketplaceService")
local RunService = game:GetService("RunService")
game.Players.PlayerAdded:Connect(function()
	local hasPass = false
	
	local success, message = pcall(function()
		hasPass = MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 11321181)
	end)
	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
		return
	end
	if hasPass == true then
		BuildPro = true
	end
end)

local UIS = game:GetService("UserInputService")
local Grid = 2
local Rot = 0

local PosX
local PosY
local PosZ
local Plot
local PlotO
local PlotX
local PlotY
local PlotZ
local Object

local GivenPlot = game.ReplicatedStorage.BuildEvents.GivenPlot
local PlaceObject = game.ReplicatedStorage.BuildEvents.PlaceObject
GivenPlot.OnClientEvent:Connect(function(plt)
	Plot = plt
	PlotO = plt.Orientation
	PlotX = PlotO.X
	PlotY = PlotO.Y
	PlotZ = PlotO.Z
end)

Plot.Touched:Connect(function(hit)
	local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if plr then
		OnPlot = true
	end
end)

local CanStart = true
local Placing = nil
local CanPlace = nil
local MoveObject = false
local CanPlace
local BuildMode = Instance.new("BoolValue")
BuildMode.Parent = Player
BuildMode = false
BuildSelection = BuildUi.ScrollingFrame
Soil = BuildSelection.SoilSelect.ImageButton

script.Parent.FHOS.Frame.Frame.BuildModeApp.TextButton.MouseButton1Click:Connect(function()
	script.Parent.FHOS.Frame.Frame.Visible = false
	script.Parent.FHOS.Frame.FhBrand.Visible = false
	script.Parent.FHOS.Frame.Power.Visible = false
	script.Parent.FHOS.Frame.Time.Visible = false
	script.Parent.FHOS.Frame.Network.Visible = false
	script.Parent.FHOS.Frame.Battery.Visible = false
	script.Parent.FHOS:TweenPosition(UDim2.new(0.105, 0,0.485, 0), "Out", "Linear", 1, false, nil)
	while script.Parent.FHOS.Rotation > -90 do
		script.Parent.FHOS.Rotation = script.Parent.FHOS.Rotation - 1
		wait()
	end
	BuildMode = true
	if BuildMode == true and OnPlot == true or BuildPro == true then
		Camera.CameraSubject = Plot
	end
end)

local function SnapToGrid()
	PosX, PosY, PosZ = math.floor(Mouse.Hit.X / Grid + .5) * Grid, math.floor(Mouse.Hit.Y / Grid + 1) * Grid, math.floor(Mouse.Hit.Z / Grid + .5) * Grid
end

local function MouseMoved()
	Object.PrimaryPart.Position = Vector3.new(PosX, PosY, PosZ)
	SnapToGrid()
end

local function CloneService(Obj)
	Object = game.ReplicatedStorage.BuildObjects:FindFirstChild(Obj):Clone()
	Object.Parent = Plot
	
	Object.PrimaryPart.Orientation = Vector3.new(PlotX, PlotY, PlotZ)
	Mouse.Move:Connect(MouseMoved)
end

Soil.MouseButton1Click:Connect(function()
	CloneService("Soil")
end)

Please give me some tips or suggestions of how to make my build system make parts stay aligned with the plot if the plot isn’t in a whole number orientation and how to save so the player rejoins can continue their plot. Hope someone has a suggestion because I’ve been researching all summer.

4 Likes

I recall trying to accomplish for years until one day in the summer around 2017 I finally figured out how to save data in TABLES!!! I didn’t know for so long, I thought you could save only strings and numbers but tables and dictionaries like what, you can save this:

local dict = {["Brown block"] = {{pos,orientation},{pos,orientation}}}

My first attempt did something like this

local saveTable = {name,pos,orientation,name,pos,orientation} -- etc

Anyways I think you should check out ego mooses placement system, as it may be long it does save the placement system.

Use remote events to fire to the server to save the placement.
Hope this helped.

3 Likes

Thanks so much for this advice. I’ve been trying this whole summer!!! Also, if you wouldn’t mind if there are multiples of a certain part then how would I save the individual part positions?

local dict = {["Brown block"] = {{pos,orientation},{pos,orientation}}}

Over here, when saving this dictionary, you could index the first object, dict[“Brown block”][1] which would be the first {pos,orientation}

This is how I would go about saving and loading placement systems, after that it is a matter of looping to get all the objects.

1 Like