Help with stacking burger ingredients

local function weldIngredient(ingredient)
	local ingredientWeld = Instance.new("WeldConstraint")
	ingredientWeld.Part0 = ingredient
	ingredientWeld.Part1 = plate.Plate

	local ingredientOffset = 0
	for _, v in ipairs(plate.Ingredients:GetChildren()) do
		ingredientOffset = ingredientOffset + v.Size.Y
	end

	ingredient.CFrame = plate.Plate.CFrame * CFrame.new(0, (plate.Plate.Size.Y + ingredientOffset), 0)
	ingredientWeld.Parent = ingredient
end

function onAddIngredients(ingredient)
	if ingredient:HasTag("Ingredient") then
		weldIngredient(ingredient)

		ingredient.Parent = plate.Ingredients
		ingredient.Massless = true
		ingredient.DragDetector:Destroy()
	end
end

I really don’t know how to use welds :sweat_smile: any help is appreciated.
Also I didn’t show it in the video but the patty is also floating a bit

You could try getting the last ingredients position and add the size.Y/2 so that the positions of the new ingredients can move up and make it in correct positions

2 Likes
local function weldIngredient(ingredient)
	local ingredientWeld = Instance.new("WeldConstraint")
	ingredientWeld.Part0 = ingredient
	ingredientWeld.Part1 = plate.Plate

	local ingredientOffset = 0
	for _, v in ipairs(plate.Ingredients:GetChildren()) do
		ingredientOffset = ingredientOffset + v.Size.Y
	end

	ingredient.CFrame = plate.Plate.CFrame * CFrame.new(0, plate.Plate.Size.Y / 2 + ingredientOffset + ingredient.Size.Y / 2, 0)
	ingredientWeld.Parent = ingredient
end

function onAddIngredients(ingredient)
	if ingredient:HasTag("Ingredient") then
		weldIngredient(ingredient)
		
		ingredient.Parent = plate.Ingredients
		ingredient.Massless = true
		ingredient.DragDetector:Destroy()
	end
end

image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.