I’m trying to create a system where when the part drops into the collector, the part gets added to the “stack”. I have the stack here:
(The dark gray part on the right is where I want my “pizzas” to stack)
I have this code that adds a pizza every time something gets collected through the collector, which works fine.
local value = game.Workspace.Models.DroppedPizzaCollector.Value
local pizza = game.ServerStorage.Pizza
local pizzaplate = game.Workspace.Models.PizzaPlate
value.Changed:Connect(function()
local clone = pizza:Clone()
clone.Anchored = true
clone.Parent = game.Workspace.Models
-- Match position
clone.Position = Vector3.new(
pizzaplate.Position.X,
pizzaplate.Position.Y,
pizzaplate.Position.Z
)
-- Match size
clone.Size = pizzaplate.Size
print("changed")
end)
However, it’s the positioning part that’s hard. How can I code this Y value to make it so that each ‘pizza’ lays directly on top of each other, eventually creating a tower?
1 Like
Add pizzaplate.Size.Y onto where you set your clone position.Y so it would be
clone.Position = Vector3.new(
pizzaplate.Position.X,
pizzaplate.Position.Y + pizzaplate.Size.Y,
pizzaplate.Position.Z
)
Tell me if this works, this is my first time commenting so this is probably not a professional way of commenting but whatever
Doesn’t seem to work unfortunately.
I just realised your cloning pizza not pizzaplate, try adding pizza.Size.Y instead of
pizzaplate.Size.Y
Same effect, the pizza is just hovering over the other one. The rest seem to spawn in the same location as the top one…
Try this
local stack = {}
value.Changed:Connect(function()
local prevstack = stack[#stack] or pizzaplate
local clone = pizza:Clone()
clone.Anchored = true
clone.Parent = game.Workspace.Models
table.insert(stack, clone)
-- Match size
clone.Size = pizzaplate.Size
-- Match position
clone.Position = Vector3.new(
pizzaplate.Position.X,
prevstack.Position.Y + clone.Size.Y,
pizzaplate.Position.Z
)
print("changed")
end)
Guy, the simplest way is to put:
clone.Position = Vector3.new(
pizzaplate.Position.X,
pizzaplate.Position.Y + 0.1,
pizzaplate.Position.Z
)
Getting somewhere! But it ended up stacking really far apart,
This would only work once, because when I try to stack the second pizza on another one it’ll just be at the same location. Because the position of the plate + 0.1 is basically still a set position that isn’t changing depending on the last pizzas location.
sorry, change the line when positioning Y
prevstack.Position.Y + (prevstack.Size.Y / 2) + (clone.Size.Y / 2),
Same results, stacking far apart… maybe there’s a way to update a variable with the location of the latest added part and just add +1? Just an idea from someone who’s not very good at math so I’m probably wrong 
Hover over the pizza object is the blue outline taller than the object itself?
So, you can make something like this:
-- Services
local Workspace = game:GetService("Workspace")
local ServerStorage = game:GetService("ServerStorage")
-- References
local modelsFolder = Workspace:WaitForChild("Models")
local droppedPizzaCollector = modelsFolder:WaitForChild("DroppedPizzaCollector")
local value = droppedPizzaCollector:WaitForChild("Value")
local pizzaTemplate = ServerStorage:WaitForChild("Pizza")
local pizzaPlate = modelsFolder:WaitForChild("PizzaPlate")
-- Stack counter
local stackHeight = 0
-- Listener
value.Changed:Connect(function()
local clone = pizzaTemplate:Clone()
clone.Anchored = true
clone.Size = pizzaPlate.Size
-- Position on top of the stack
local basePos = pizzaPlate.Position
local newY = basePos.Y + (stackHeight * clone.Size.Y)
clone.Position = Vector3.new(basePos.X, newY, basePos.Z)
clone.Parent = modelsFolder
stackHeight += 1
print("Pizza added to stack:", stackHeight)
end)
Seems to be the same issue of stacking far apart, however it’s getting better from the original issue! I have faith 
No, it’s not 
You could do that but just in case you’d want a thicker pizza. Though, like you said, if simplicity is your goal you could do + 0.1 value.
'lThe issue might be your pizza’s size, could we have more information about the pizza’s properties. Is it only a single part?
Definitely my bad, I was real stupid to not noticed your Models have everything else in there too. 
This is the new script, and Roblox Place File with the suppose hierarchy of your models, it should work.
local SPACE_BETWEEN_PIZZA = 0.025
local pizzaPlateOriginalInformation = {
Position = game.Workspace.Models.PizzaPlate.Position,
Size = game.Workspace.Models.PizzaPlate.Size,
}
local pizzasInWorkspace = game.Workspace.Models --This should be renamed to a say PizzaStacks instead ngl
local pizzaTemplate = game.ServerStorage.Pizza
local checkValue = game.Workspace.Models.DroppedPizzaCollector.Value
local collectedPizzas = 0
local function _buildStackOfPizzas()
local newPizza = pizzaTemplate:Clone()
local pizzaGap = SPACE_BETWEEN_PIZZA + pizzaTemplate.Size.X
newPizza.Position = pizzaPlateOriginalInformation.Position + Vector3.new(0, collectedPizzas * pizzaGap, 0)
newPizza.Parent = pizzasInWorkspace
end
-- Match size, is this needed?
pizzaTemplate.Size = pizzaPlateOriginalInformation.Size
checkValue.Changed:Connect(function()
collectedPizzas += 1
_buildStackOfPizzas()
print("Added another pizza to stack")
end)
Place File -
Stack Pizza.rbxl (54.3 KB)
It works but my pizza model doesn’t revert to it’s original size, I actually make the stacking pizza bigger
pizzaTemplate.Size = pizzaPlateOriginalInformation.Size
But it doesn’t set back when I use the original pizza model for the actual tycoon dropper model. They’re the same model, I’m just cloning it and changing it. But with your script my modifications affect the original part that was cloned, too.
By reading your script, it would seem you want the new pizza onto your pizza stack, matching the pizzaPlate size, or that isn’t the case?
Because the pizza plate doesn’t look like same size to the pizza dough on your screenshot, the pizzadough (on the left) is quite lot smaller and thicker.
You can just delete the line, so the pizza is same size as the Pizza Template, not the Pizza Plate. That line is there because in your original script, it set pizza’s size to PizzaPlate size instead of the pizza came out of the tycoon dropper.
pizzaTemplate.Size = pizzaPlateOriginalInformation.Size
The stacking isn’t really working, it’s on top of them, but when it spawns, it just falls through and then clips the other pizza.