Weird CFrame problem!

I don’t know why this doesnt work can someone help me!?!

this is the workspace:
Schermopname (21)
and the script!

	for i,v in pairs(winnersPlace:GetChildren()) do
		local amountRows = #platesFolder:GetChildren()
		local lastRow = platesFolder:FindFirstChild("Row"..tostring(amountRows))
		local lastPlate = lastRow:FindFirstChild("Plate")
		if v.Name == "Meshes/IceysAssetPack_Cylinder (1)" or v.Name == "Meshes/IceysAssetPack_Cylinder.037 (1)" then
			local oldYPos = v.CFrame.Position.Y
			local oldZPos = v.CFrame.Position.Z
			local newXPos = lastPlate.CFrame.Position.X + 33.6
			local oldRotation = v.CFrame.Rotation

			v.CFrame = CFrame.new(newXPos, oldYPos, oldZPos) * CFrame.new(0, -65, 0)
		elseif v.Name == "WinnersPart" then
			local oldYAngle = 0
			local oldYPos = v.CFrame.Position.Y
			local oldZPos = v.CFrame.Position.Z
			local newXPos = lastPlate.CFrame.Position.X + 33.6
			local oldRotation = v.CFrame.Rotation

			v.CFrame = CFrame.new(newXPos, oldYPos, oldZPos) * CFrame.new(0, 0, 0)
		end
	end

Please describe the issue in some way, I don’t really understand the current expected result of the code & what goes wrong

1 Like

maybe cuz it have two cframes

for i,v in pairs(winnersPlace:GetChildren()) do
		local amountRows = #platesFolder:GetChildren()
		local lastRow = platesFolder:FindFirstChild("Row"..tostring(amountRows))
		local lastPlate = lastRow:FindFirstChild("Plate")
		if v.Name == "Meshes/IceysAssetPack_Cylinder (1)" or v.Name == "Meshes/IceysAssetPack_Cylinder.037 (1)" then
			local oldYPos = v.CFrame.Position.Y
			local oldZPos = v.CFrame.Position.Z
			local newXPos = lastPlate.CFrame.Position.X + 33.6
			local oldRotation = v.CFrame.Rotation

			v.CFrame = CFrame.new(newXPos, oldYPos, oldZPos) 
		elseif v.Name == "WinnersPart" then
			local oldYAngle = 0
			local oldYPos = v.CFrame.Position.Y
			local oldZPos = v.CFrame.Position.Z
			local newXPos = lastPlate.CFrame.Position.X + 33.6
			local oldRotation = v.CFrame.Rotation

			v.CFrame = CFrame.new(newXPos, oldYPos, oldZPos)
		end
	end

It appears you are trying to adjust the position of different parts in your game, and you’re encountering some issues. Without a bit more detail about the issue you’re experiencing, it can be difficult to provide specific guidance, but I can point out a few things that might be causing problems based on your script.

  1. CFrame Initialization: You seem to be creating a new CFrame with the new X, old Y, and old Z coordinates and then multiplying it by another CFrame created with (0, -65, 0) or (0, 0, 0) in the case of “WinnersPart”. The multiplication here might not be necessary, depending on what you’re trying to achieve.
  2. CFrame Multiplication: When multiplying CFrames, you’re performing a transformation. In your case, multiplying by CFrame.new(0, -65, 0) will move the part 65 studs down. If you’re trying to just position the part without any rotation, you can set the CFrame directly without multiplication.
  3. Unchanged Variables: You’ve assigned values to oldRotation and oldYAngle but they aren’t used elsewhere in the script. If you’re trying to preserve the original rotation of your objects, you’ll need to incorporate these into your CFrame calculations.
for i,v in pairs(winnersPlace:GetChildren()) do
	local amountRows = #platesFolder:GetChildren()
	local lastRow = platesFolder:FindFirstChild("Row"..tostring(amountRows))
	local lastPlate = lastRow:FindFirstChild("Plate")
	local newXPos = lastPlate.CFrame.Position.X + 33.6
	if v.Name == "Meshes/IceysAssetPack_Cylinder (1)" or v.Name == "Meshes/IceysAssetPack_Cylinder.037 (1)" then
		v.CFrame = CFrame.new(newXPos, v.CFrame.Y, v.CFrame.Z)
	elseif v.Name == "WinnersPart" then
		v.CFrame = CFrame.new(newXPos, v.CFrame.Y, v.CFrame.Z)
	end
end

In this code, I’ve removed the second CFrame multiplication. If you find that you still need to move the cylinder 65 studs downwards, you can adjust v.CFrame.Y directly in the CFrame creation for the cylinder:

v.CFrame = CFrame.new(newXPos, v.CFrame.Y - 65, v.CFrame.Z)