How would I make parts shoot out from the player until they hit something? (Another player or part)

Hello, I am trying to make multiple parts move around the player in a circle motion and after it makes a full loop around the player it shoots out and moves until it hits something.

I’ve currently got parts to surround the player in a circle and move with the player but not spin or shoot.
Here is the code: (It goes in StarterCharacterScripts)

local PARTS = {}
local fullCircle = 2 * math.pi

wait(2)		-- So we can watch it once we load in

for I=0, 12 do
	local PART = Instance.new("Part")
	PART.Shape = Enum.PartType.Ball
	PART.Anchored = true
	PART.CanCollide = false
	PART.Parent = workspace
	PARTS[#PARTS+1] = PART
end

local function getXAndZPositions(ANGLE, RADIUS)
	RADIUS = RADIUS or 5
	local x = math.cos(ANGLE) * RADIUS
	local z = math.sin(ANGLE) * RADIUS
	return x, z
end

for O=0, 360 do
	for i, part in pairs(PARTS) do
		local angle = i * (fullCircle / #PARTS) - i
		local x, z = getXAndZPositions(angle)
		local position = (script.Parent.HumanoidRootPart.CFrame * CFrame.new(x, 0, z)).p
		part.CFrame = CFrame.new(position)
	end
	wait()
end

Any help will be greatly appreciated!
Thank you, Zonix.

  1. To make them spin you have to connect to the RunService step function and then
    accumulate delta time in some variable and then do this: local angle = i * (fullCircle / #PARTS) - i + accumulatedDeltaTime.

  2. To shoot them out you will need to stop modifying the CFrame and add a BodyVelocity as a child of each part and then set the velocity parameters (and the parent to the part you wish to shoot) to the BodyVelocity.

2 Likes