Here’s what your code is doing.
You initially set RayDirection to 0 in your while loop, so this is what happens:
Then, you add 30 studs to the y-component of the vector:
Then you add another 30 upwards (you don’t rotate the vector by 30 degrees; you’re just making it point more upwards by 30 studs):
What happens when RayDirection = 330:
What do you mean by this? You can map integers to individual positions, but a position in 3D is a vector because you need one coordinate for every axis. You seem to be mixing up concepts.
CFrames (short for CoordinateFrame) represent coordinate systems, but they also represent transformations like translation or rotation (something you learn in linear algebra and computer graphics). In this case you use CFrames to rotate the direction of the raycast. For example, you can rotate a vector about the x-axis by applying a rotation transformation:
local part = workspace.Part -- any part
local v = Vector3.new(0, 0, -1)
local angle = 30 -- degrees
local oneStudInFont = part.CFrame * v -- this is the position 1 stud in front of the part
local rotatedVector = CFrame.Angles(math.rad(angle), 0, 0) * v -- this just means "rotate the vector v by 30 degrees about the world x-axis"
local rotatedVectorRelativeToPart = part.CFrame * CFrame.Angles(math.rad(angle), 0, 0) * v -- this means "take the vector v, rotate it by 30 degrees, then translate the vector so that it is relative to the part's coordinate frame (object space of part)"
These are just some examples. In @Razor_IB’s example, the approach looks a bit different, but it’s following the same idea.
Example
Here is an example of how to spawn a circle of parts around another part:
local angle = -30
local p = workspace.Part -- red part in screenshot
while angle < 360 do
local clone = p:Clone()
clone.Color = Color3.new(0, 1, 0)
clone.Position = p.CFrame * CFrame.Angles(math.rad(angle), 0, 0) * Vector3.new(0,0,5)
clone.Parent = workspace
angle += 30
wait(1)
end
No matter how the red part is orientated, the circle of parts will always spawn relative to its position and orientation. Here I rotated the red part to show how the ring follows its orientation: