CFrames problem

I’m working on a Roblox script specifically with CFrames that randomly select a spot and places a “Page” that is a simple block with a texture. That’s the script:

local Bathrooms = {
	CFrame.new(-685.361, 13.321, -330.089) * CFrame.fromEulerAnglesXYZ(math.rad(-0.012), math.rad(-89.939), math.rad(11.365)), 
	CFrame.new(-729.244, 14.954, -324.809) * CFrame.fromEulerAnglesXYZ(math.rad(-0.013), math.rad(-89.939), math.rad(12.053)),
	CFrame.new(-722.548, 14.472, -411.221) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(0), math.rad(15.908)),
	CFrame.new(-689.109, 14.253, -411.221) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(0), math.rad(-9.855))
}

local CuttedTrees = {
	CFrame.new(-383.196, 13.448, -557.085) * CFrame.fromEulerAnglesXYZ(math.rad(5.312), math.rad(43.756), math.rad(-8.425)),
	CFrame.new(-393.5, 13.448, -533.868) * CFrame.fromEulerAnglesXYZ(math.rad(0.001), math.rad(18.745), math.rad(-10.233)),
	CFrame.new(-408.502, 15.015, -506.009) * CFrame.fromEulerAnglesXYZ(math.rad(0.56), math.rad(21.411), math.rad(-7.856)),
	CFrame.new(-420.613, 15.015, -545.446) * CFrame.fromEulerAnglesXYZ(math.rad(-7.267), math.rad(25.486), math.rad(-11.571))
}

local BlueTruck = {
	CFrame.new(-875.301, 11.608, -521.596) * CFrame.fromEulerAnglesXYZ(math.rad(-2.781), math.rad(29.295), math.rad(12.484)),
	CFrame.new(-878.194, 11.608, -527.764) * CFrame.fromEulerAnglesXYZ(math.rad(-2.781), math.rad(6.511), math.rad(12.484)),
	CFrame.new(-874.742, 12.352, -525.018) * CFrame.fromEulerAnglesXYZ(math.rad(42.034), math.rad(-62.501), math.rad(17.313)),
	CFrame.new(-889.635, 12.801, -518.386) * CFrame.fromEulerAnglesXYZ(math.rad(2.583), math.rad(-64.862), math.rad(9.093))
}

local TruckHouse = {
	CFrame.new(-984.41, 13.392, -253.976) * CFrame.fromEulerAnglesXYZ(math.rad(-0.911), math.rad(-99.083), math.rad(8.319)),
	CFrame.new(-1003.192, 14.332, -253.976) * CFrame.fromEulerAnglesXYZ(math.rad(-0.911), math.rad(-99.083), math.rad(8.319)),
	CFrame.new(-995.652, 13.71, -247.837) * CFrame.fromEulerAnglesXYZ(math.rad(-1.043), math.rad(-9.239), math.rad(-13.626)),
	CFrame.new(-977.826, 11.989, -242.352) * CFrame.fromEulerAnglesXYZ(math.rad(-3.35), math.rad(-105.397), math.rad(-5.956))
}

local Silos = {
	CFrame.new(-325.127, 14.381, -127.12) * CFrame.fromEulerAnglesXYZ(math.rad(-0.06), math.rad(-134.979), math.rad(-8.633)),
	CFrame.new(-323.64, 14.336, -136.411) * CFrame.fromEulerAnglesXYZ(math.rad(0.061), math.rad(-60.012), math.rad(-7.644)),
	CFrame.new(-330.751, 14.641, -140.78) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(0), math.rad(-16.183)),
	CFrame.new(-338.502, 15.034, -134.877) * CFrame.fromEulerAnglesXYZ(math.rad(0.035), math.rad(74.852), math.rad(-8.079))
}

local IntersectedWalls = {
	CFrame.new(-203.161, 14.638, -597.254) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(90), math.rad(-18.267)),
	CFrame.new(-216.5, 12.603, -618.907) * CFrame.fromEulerAnglesXYZ(math.rad(0.137), math.rad(-175.281), math.rad(-9.006)),
	CFrame.new(-203.161, 14.514, -633.517) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-90), math.rad(-14.15)),
	CFrame.new(-188.274, 14.817, -623.277) * CFrame.fromEulerAnglesXYZ(math.rad(0.077), math.rad(-175.302), math.rad(-5.706))
}

local RockPoint = {
	CFrame.new(-157.625, 12.746, -276.645) * CFrame.fromEulerAnglesXYZ(math.rad(33.55), math.rad(99.216), math.rad(0.663)),
	CFrame.new(-191.589, 12.082, -284.732) * CFrame.fromEulerAnglesXYZ(math.rad(-27.152), math.rad(-96.75), math.rad(-1.171)),
	CFrame.new(-221.551, 13.52, -237.799) * CFrame.fromEulerAnglesXYZ(math.rad(9.133), math.rad(-103.677), math.rad(-7.729)),
	CFrame.new(-191.329, 14.427, -219.731) * CFrame.fromEulerAnglesXYZ(math.rad(13.318), math.rad(42.865), math.rad(0.278))
}

local ScaryTree = {
	CFrame.new(-785.002, 13.192, -173.349) * CFrame.fromEulerAnglesXYZ(math.rad(-5.42), math.rad(68.521), math.rad(-5.317)),
	CFrame.new(-790.634, 13.827, -171.075) * CFrame.fromEulerAnglesXYZ(math.rad(-1.376), math.rad(-10.186), math.rad(-5.891)),
	CFrame.new(-793.701, 13.22, -174.581) * CFrame.fromEulerAnglesXYZ(math.rad(3.177), math.rad(-63.963), math.rad(-4.832)),
	CFrame.new(-791.592, 13.101, -179.938) * CFrame.fromEulerAnglesXYZ(math.rad(-14.824), math.rad(-158.293), math.rad(-8.765))
}

local Tunnel = {
	CFrame.new(-505.754, 12.667, -614.918) * CFrame.fromEulerAnglesXYZ(math.rad(0.067), math.rad(-141.607), math.rad(8.43)),
	CFrame.new(-554.854, 12.696, -576.072) * CFrame.fromEulerAnglesXYZ(math.rad(0.085), math.rad(-141.712), math.rad(-13.549)),
	CFrame.new(-562.201, 12.894, -621.424) * CFrame.fromEulerAnglesXYZ(math.rad(0.136), math.rad(-141.669), math.rad(-9.851))
}

local WaterSilos = {
	CFrame.new(-557.4, 13.232, -348.27) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(90), math.rad(21.153)),
	CFrame.new(-557.4, 13.386, -388.104) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(90), math.rad(-15.845)),
	CFrame.new(-517.78, 13.378, -325.748) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(90), math.rad(-16.38)),
	CFrame.new(-517.78, 13.648, -368.42) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(90), math.rad(-20.359))
}

local zonesArray = {Bathrooms, CuttedTrees, BlueTruck, TruckHouse, Silos, IntersectedWalls, RockPoint, ScaryTree, Tunnel, WaterSilos}

local pages = workspace.Pages:GetChildren()

for i=1, #pages, 1 do
	local randomZone = math.random(1, #zonesArray)
	local randomPosition = math.random(1, #zonesArray[randomZone])

	pages[i].CFrame = zonesArray[randomZone][randomPosition]
	table.remove(zonesArray, randomZone)
end

But I got some problems. For some reasons the script doesn’t set the rotation correctly only for the RockPoint Array. Those are the expected rotations and the rotations Roblox sets. Position is fine.

Expected: CFrame.new(-221.551, 13.52, -237.799) * CFrame.fromEulerAnglesXYZ(math.rad(9.133), math.rad(-103.677), math.rad(-7.729))
Used: Rotation = -2.151, -103.51, -16.607

Expected: CFrame.new(-191.589, 12.082, -284.732) * CFrame.fromEulerAnglesXYZ(math.rad(-27.152), math.rad(-96.75), math.rad(-1.171))
Used: Rotation = 3.075, -96.012, 25.819

Expected: CFrame.new(-191.329, 14.427, -219.731) * CFrame.fromEulerAnglesXYZ(math.rad(13.318), math.rad(42.865), math.rad(0.278))
Used: Rotation = 9.72, 43.645, 9.426

Expected: CFrame.new(-157.625, 12.746, -276.645) * CFrame.fromEulerAnglesXYZ(math.rad(33.55), math.rad(99.216), math.rad(0.663))
Used: Rotation = -5.078, 97.701, 33.871

I tried to change the values and hot completely different rotations now.

Expected: CFrame.new(-157.625, 12.746, -276.645) * CFrame.fromEulerAnglesXYZ(math.rad(-5.078 - 33.55), math.rad(97.701 - 99.216), math.rad(33.871 - 0.663))
Used: Rotation = -38.612, -1.939, 34.418

Expected: CFrame.new(-191.589, 12.082, -284.732) * CFrame.fromEulerAnglesXYZ(math.rad(3.075 - (-27.152)), math.rad(-96.012 - (-96.75)), math.rad(25.819 - (-1.171)))
Used: Rotation = 30.224, 0.854, 27.42

Expected: CFrame.new(-221.551, 13.52, -237.799) * CFrame.fromEulerAnglesXYZ(math.rad(-2.151 + 9.133), math.rad(-103.51 - (-103.677)), math.rad(-16.607 - (-7.729)))
Used: Rotation = 6.982, 0.168, -8.858

Expected: CFrame.new(-191.329, 14.427, -219.731) * CFrame.fromEulerAnglesXYZ(math.rad(9.72 - 13.318), math.rad(43.645 - 42.865), math.rad(9.426 - 0.278))
Used: Rotation = -3.598, 0.782, 9.099

Does anyone have any clue of why this might be happening? All the other arrays are fine. It happens only with the RockPoint one.

1 Like
1 Like

Doing this for some reasons worked only for the first CFrame in Rockpoint… I don’t know why it doesn’t for the others…

EDIT: It worked for all of them! I just had to put the Y first and then X and Z. I don’t know what’s the difference between this and the normal way but this worked.

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