# Help with making an automatic plate generator

I have been trying to figure out how I could create a plate placing system similar to plates of fate, but I could only get so far until I came across a few issues. I am having trouble with placing the plates in rows and columns, and actually doing the math to place the plate. Here’s what I tried doing to get it working. (it’s not complete because I couldn’t find the right formula for the positioning of the plates to locate them.)

``````local PlateAdder = {}

function PlacePlate(player)

local plate = Instance.new("Part")
plate.Name = player.Name.."'s_Plate"
plate.Size = Vector3.new(20,1,20)
plate.Material = Enum.Material.Grass
plate.Color = Color3.fromRGB(124, 156, 107)

spawn(function()
for i,plr in pairs(game:GetService("Players"):GetPlayers()) do
if plr then
local newPlate = plate:Clone()
newPlate.Parent = workspace.Plates
newPlate.Position = Vector3.new((-42/(i*3)), 0.5, -183.25)
end
end
end)
end

``````
1 Like

wouldn’t you have to do this for z as well, columns and rows ryt?

Rows in columns going horizontally I meant, sorry I also didn’t get to finish the math for the x, so that’s why the z isn’t done…

1 Like

I hate to be that guy who just links posts without any explanation but here I go anyway.

In the rbxl file above, you can find a script for tile generation used for A* pathfinding.
I modified the code so that it works for tile generation like in your case.

Server script

``````local TileX, TileY = 10, 10 -- number of tiles along both the x and y axis

local Rows, Cols = TileX, TileY

local HexMap = {}

local function StartGenerate()
for x=1, Rows do	-- number of rows we'll create
HexMap[x] = {}

for y = 1, Cols do
local End = false -- End can be eitheir the start or final tile

if x == 1 and y == 1 then	-- Starting tile
End = true
end
if x == Rows and y == Cols then	-- End tile
End = true
end

HexMap[x][y] = NodeModule.new(x,y,End) -- Generate a new tile object
end
end
for x=1, Rows do
for y = 1, Cols do
HexMap[x][y]:Create()	-- set its CFrame
end
if x%5 == 0 then	-- modulus, Im not good enough at maths to know what it actually does
wait(.1)
end
end
end

StartGenerate()
``````

Module script

``````-- Length and width of one tile
local tileWidth = 4
local tileHeight = 4

local Node = {}

Node.__index = Node

local RandomClass = Random.new()	-- Create a random seed

function Node.new(x, y, End)
local self = setmetatable({},Node)

self.x = x
self.y = y

return self
end

function Node:Create()
if not self.Instance then	-- Check that there is no existing hex
local Part = workspace.Folder:WaitForChild("Tile"):Clone()
Part:SetPrimaryPartCFrame(CFrame.new(self.x*tileWidth, 1, self.y*tileHeight))
Part.Parent = workspace:WaitForChild("Map")

self.Instance = Part
end
end

return Node
``````

To add padding between plates, you could change the CFrame you set the tile at. E.g,
`self.x*tileWidth*2, 1, self.y*tileHeight*2` to create a gap the size of one tile between each tile.

2 Likes

The Node Module isn’t defined in the server script, should I do that?

1 Like

A few stuff in the code I posted need to be filled out by yourself.
E.g:

1. create and define the node module
2. Define the plate which you will clone to the game here:

And create a folder named “Map” to store the plates in.

The last two are completely optional and you can do it whichever way you want.
There might be some other stuff I’ve missed out which you’ll need to modify for your own game.

1 Like

It works, thanks for the help man

1 Like