Barrage hands help

Hi, I am currently making a barrage and cant get the rotation working.
Here is what is happening : Jojo_ Fallen Fate - Roblox Studio 2023-02-15 16-04-26

The code

local RunService = game:GetService("RunService")
local arm = workspace.Hand

function quadBezier(t, p0, p1, p2)
	local Position = (1 - t)^2 * p0 + 2 * (1 - t) * t * p1 + t^2 * p2
	return Position
end

local function MoveArm(clone : Model)
	local rand = math.random(1,3)
	local P0 = workspace["Barrage"..rand].P0.Position
	local P1 = workspace["Barrage"..rand].P1.Position
	local P2 = workspace["Barrage"..rand].P2.Position
	local Position = quadBezier(1,P0,P1,P2)
	local X1,Y1,Z1,X2,Y2,Z2
	local StartAngles
	local EndAngles
	if rand == 1 then
		X1,Y1,Z1 = 0,0,135
		StartAngles = CFrame.Angles(0,0,135)
		EndAngles = CFrame.Angles(0,0,45)
		X2,Y2,Z2 = 0,0,45
	elseif rand == 2 then
		X1,Y1,Z1 = 0,-45,90
		StartAngles = CFrame.Angles(0,-45,90)
		EndAngles = CFrame.Angles(-60,45,0)
		X2,Y2,Z2 = -60,45,0
	elseif rand == 3 then
		X1,Y1,Z1 = 0,45,135
		StartAngles = CFrame.Angles(0,45,135)
		EndAngles = CFrame.Angles(0,45,60)
		X2,Y2,Z2 = 0,45,60
	end
	local StartCFrame = CFrame.new(quadBezier(0,P0,P1,P2)) * StartAngles
	local EndCFrame = CFrame.new(Position) * EndAngles
	local LerpTime = .7
	local StartTime = os.clock()
	local TimeSpent = 0
	local Lerp
	Lerp = RunService.Heartbeat:Connect(function(deltaTime)
		TimeSpent += deltaTime
		local alpha = TimeSpent / LerpTime
		if alpha >= 1 then
			Lerp:Disconnect()
		else
			local LerpNew = StartAngles:Lerp(EndAngles,alpha)
			clone.PrimaryPart.CFrame = CFrame.new(quadBezier(alpha,P0,P1,P2)) * LerpNew.Rotation
		end
	end)
end
1 Like