Alrighty, so I'm workin' on somethin' special and I want to create a circle of cubes 'round my player. My current code:


function createNewCube(Type, Text, Player, isParent, pos)
	local cube = Instance.new("Part")
	cube.Size = Vector3.new(1,1,1)
	cube.Anchored = true
	cube.CanCollide = false
	cube.BackSurface = Enum.SurfaceType.SmoothNoOutlines
	cube.TopSurface = Enum.SurfaceType.SmoothNoOutlines
	cube.BottomSurface = Enum.SurfaceType.SmoothNoOutlines
	cube.FrontSurface = Enum.SurfaceType.SmoothNoOutlines
	cube.LeftSurface = Enum.SurfaceType.SmoothNoOutlines
	cube.RightSurface = Enum.SurfaceType.SmoothNoOutlines
	cube.Parent = Player.Character
	cube.CFrame = cube.CFrame * CFrame.Angles(math.rad(math.random(1,180)), math.rad(math.random(1,180)), math.rad(math.random(1,180)))
	cube.BrickColor = BrickColor.new("Bright red")
	
	cube.Position = Player.Character.HumanoidRootPart.Position + pos
	
	local BV = Instance.new("BodyPosition")
	BV.MaxForce = Vector3.new(10000,10000,10000)
	BV.P = 10000
	BV.D = 1250
	BV.Position = Player.Character.HumanoidRootPart.Position + pos
	BV.Parent = cube
	
	local c = script.CubePositionScript:Clone()
	c.Parent = cube
	c.Position.Value = pos
	c.Disabled = false

	cube.Anchored = false
	
	local cd = nil
	
	if isParent then
		
		cd = Instance.new("ClickDetector")
		cd.Parent = cube
		
	end
	
	return cube,cd
end


-- This is the main part I'm having trouble with (the math for making the cubes spawn in a ring around the player):
-- createNewCube() is above, and basically just makes a new cube and positions it where I tell it to.
local x,z = 10,0

for i=0,20,1 do
	createNewCube("wah", "adw", plr, true, Vector3.new(x-i,0,z+i)) -- The cube is positioned at Vector3.new(x-i, 0, z+i). This only makes a straight line. How can I make a circle?
	wait()
end

2 comments

0

Also, I removed a bit of code. plr is an actual variable I just removed the code where the plr variable is given. This doesn't cause any errors ;)

0