Expected: Grid, Results: Not Grid

Hello developers
im making a dance pad or something that i don’t know but my problem is, my script supposed to make a grid for the dance pad, instead its something. What I’m trying to do is cloning the group and change the children’s position by adding a Z on it. Im not too familiar in Workspace scripting cause I’m more into GUI scripting, so thank you for the help and i really appreciate it!

Script:

-- Settings
local TileOutline = false
local TileLight = false
local TileMaterial = Enum.Material.Neon
local TileAspectRatio = 4
local TilePadding = 0
local StartingPos = Vector3.new(0, 0, 0)
local X_length = 10
local Z_length = 10
local LastXPos = Vector3.new(0, 0, 0)
-- Set up
local TileFolder = Instance.new("Folder", Workspace)
TileFolder.Name = "DancePad"
for Load_X = 1, X_length do
	print(Load_X)
	local PartLoader = Instance.new("Part", TileFolder)
	PartLoader.Position = LastXPos + Vector3.new(TileAspectRatio + TilePadding, StartingPos.Y, StartingPos.Z) 
	PartLoader.Anchored = true
	PartLoader.Size = Vector3.new(TileAspectRatio, 0.25,TileAspectRatio)
	PartLoader.Material = TileMaterial
	PartLoader.BrickColor = BrickColor.Black() -- Starting Color
	LastXPos = PartLoader.Position
	task.wait(0.1)
end
local RowGroup = Instance.new("Model", TileFolder)
RowGroup.Name = "RowGroup"
for _, GroupParts in pairs(TileFolder:GetChildren()) do
	if GroupParts:IsA("Part") then
		GroupParts.Parent = RowGroup
	end
end
local LastZPos = Vector3.new(0, 0, 0)
for Load_Z = 1, Z_length - 1 do
	local NewRow_Z = RowGroup:Clone()
	NewRow_Z.Name = NewRow_Z.Name..Load_Z
	NewRow_Z.Parent = TileFolder
	for _, ChangePadPos in pairs(NewRow_Z:GetChildren()) do
		ChangePadPos.Position = LastZPos + Vector3.new(ChangePadPos.Position.X, 0, TileAspectRatio + TilePadding) 
		LastZPos = ChangePadPos.Position
	end
end

Expected:
Grid
Results:
Not grid

Line I’m confused on:

local LastZPos = Vector3.new(0, 0, 0)
for Load_Z = 1, Z_length - 1 do
	local NewRow_Z = RowGroup:Clone()
	NewRow_Z.Name = NewRow_Z.Name..Load_Z
	NewRow_Z.Parent = TileFolder
	for _, ChangePadPos in pairs(NewRow_Z:GetChildren()) do
		ChangePadPos.Position = LastZPos + Vector3.new(ChangePadPos.Position.X, 0, TileAspectRatio + TilePadding) 
		LastZPos = ChangePadPos.Position
	end
end

Also if i change ChangePadPos.Position.X to 0 in line 38, it will just make it like this:

The issue is stemming from setting the position relative to the previous position. The effect of this is compounding absolute offsets (your starting position values) into larger values that give you the “trail” you’re seeing. Instead, use your Load_X and Load_Z variables to scale the dynamic part of your assignment and keep everything else the same, like this:

-- Settings
local TileOutline = false
local TileLight = false
local TileMaterial = Enum.Material.Neon
local TileAspectRatio = 4
local TilePadding = 0
local StartingPos = Vector3.new(0, 0, 0)
local X_length = 10
local Z_length = 10

local AbsoluteTileSpacing = TileAspectRatio + TilePadding

-- Set up
local TileFolder = Instance.new("Folder")
TileFolder.Name = "DancePad"

for Load_X = 1, X_length do
	print(Load_X)
	local PartLoader = Instance.new("Part")
	PartLoader.Position = Vector3.new(AbsoluteTileSpacing*(Load_X-1),StartingPos.Y,StartingPos.Z)
	PartLoader.Anchored = true
	PartLoader.Size = Vector3.new(TileAspectRatio, 0.25,TileAspectRatio)
	PartLoader.Material = TileMaterial
	PartLoader.BrickColor = BrickColor.Black() -- Starting Color
	LastXPos = PartLoader.Position
	
	PartLoader.Parent = TileFolder
	--task.wait(0.1)
end
local RowGroup = Instance.new("Model")
RowGroup.Name = "RowGroup"
for _, GroupParts in pairs(TileFolder:GetChildren()) do
	if GroupParts:IsA("Part") then
		GroupParts.Parent = RowGroup
	end
end
RowGroup.Parent = TileFolder

for Load_Z = 1, Z_length - 1 do
	local NewRow_Z = RowGroup:Clone()
	NewRow_Z.Name = NewRow_Z.Name..Load_Z
	NewRow_Z.Parent = TileFolder
	for _, ChangePadPos in pairs(NewRow_Z:GetChildren()) do
		ChangePadPos.Position = Vector3.new(ChangePadPos.Position.X, 0, AbsoluteTileSpacing * Load_Z) 
	end
end

--Assign the parent of TileFolder as your last action so that all of the
--changes are applied in one packet when sending to the client.
TileFolder.Parent = workspace

As an aside, avoid setting the Parent property of objects to before setting their other properties. This is less of a problem when working on the client, but it can potentially result in additional update packets when done from the server, as those property changes may happen after the packets for inserting the objects occurs. If the properties are assigned prior to the time of insertion, the entire update can happen at once.

I’m assuming you’re trying to make a dance floor with 4x4 pads that flash different colours.
That being said why are you trying to place all these pads with a script?
You should probably just make a model with all the pads in it, with all the Properties of those Parts built in, then use a script to change the pad Part’s colours.
You could spawn the entire dance floor model in if you need to.

1 Like

It works thank you so much!

I’m not using 4x4 pads, the pad size are X_lengthxZ_length at the settings, and customizable.

1 Like