So I know something is wrong with the math for the x and z parts of the CFrame, but I can't seem to figure out what the problem is. Its making what is supposed to be a sphere into a cylinder instead because the rings at the top aren't getting closer to each other. Currently its making the "sphere" look like this
Here is the code:
rings = 12 segs = 16 r = 20 -- radius center = workspace.Core.PrimaryPart.Position -- The center of the sphere, which can be any vector3 value for i = -90,90,180/rings do for j = 0,360 - (360/segs),360/segs do part = Instance.new("Part") part.Name = "SphereWall" part.CanCollide = true part.Anchored = true part.Size = Vector3.new(4,4,1) part.CFrame = CFrame.new(Vector3.new( center.X + (math.cos(math.rad(j)) * r), center.Y + (math.sin(math.rad(i)) * r), center.Z + (math.sin(math.rad(j)) * r)), center) part.Parent = script.Parent end end
Well after enough searching around, i found a solution (The link is to stackoverflow.com) and applied it in this code if anyone wants to use it, since there aren't any hollow sphere generators I could find on the web:
ri = 12 se = 16 r = 40 center = workspace.Core.PrimaryPart.Position for i = 0,ri do for j = 0,se - 1 do local part = Instance.new("Part") part.Name = "SphereWall" part.CanCollide = true part.Anchored = true local s = Enum.SurfaceType.SmoothNoOutlines part.TopSurface = s part.BottomSurface = s part.RightSurface = s part.LeftSurface = s part.FrontSurface = s part.BackSurface = s local c = 10 --(2*math.pi*r)/(360/r) part.Size = Vector3.new(c,c,1) part.CFrame = CFrame.new(Vector3.new( center.X + math.sin(math.pi * (i/ri)) * math.cos(math.pi*2 * (j/se)) * r, center.Y + math.cos(math.pi * (i/ri)) * r, center.Z + math.sin(math.pi * (i/ri)) * math.sin(math.pi*2 * (j/se)) * r), center) part.Parent = script.Parent end end
Also, the result of the script looks like this