Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to lerp a table of parts to your mouse position?

I have a long strand of parts that for now is linked to your torso and moves according to the song played (audio visualizer thing) but I wanted to change it so instead it moved each block (still in a line) to your mouse

  for i = 1, #Parts2 do
    if i == 1 then
      Parts2[i].CFrame = Parts2[i].CFrame:lerp(game.Players.LocalPlayer.Character.Torso.CFrame+Vector3.new(0,.75,0), 0.9)
    else
      Parts2[i].CFrame = Parts2[i].CFrame:lerp(Parts2[i - 1].CFrame * CFrame.Angles(-loudness / 10, math.sin(-loudness / 1000000000), 0) * CFrame.new(0, 0, 0.15), 0.8)
    end
  end

Thats my current code, if you could help me with having it lerp to my mouse it would be great.

1 comment

0

The table is made before this

1 answer

You could use the MouseMoved event to detect when the mouse moves, and then group the parts in a model and use the SetPrimaryPartCFrame function to move them.

Note: Remeber to use variables to keep your code clean and organised.

local plr = game.Players.LocalPlayer
local m = plr:GetMouse()
local parts --This is your model of the parts.

repeat wait() until plr.Character

local char = plr.Character
local tor = char:WaitForChild("Torso")
local offset = CFrame.Angles(-loudness / 10, math.sin(-loudness / 1000000000), 0)

function visualize()
	for i = 1, #Parts2 do
		if i == 1 then
			Parts2[i].CFrame = Parts2[i].CFrame:lerp(
				tor.CFrame+Vector3.new(0,.75,0), 
				0.9
			)
		else
			Parts2[i].CFrame = Parts2[i].CFrame:lerp(
				Parts2[i - 1].CFrame * offset * CFrame.new(0, 0, 0.15), 
				0.8
			)
		end
	end
end

m.MouseMoved:Connect(function()
	local spot = m.Hit;
	parts:SetPrimaryPartCFrame(spot)
end)

while wait(.1) do
	visualize()
end

5 comments

0

I changed that code to that but now the parts dont even show up (they are supposed to be connected to the torso too, I think you've done that, but I had to of these, and I changed one part and not both aren't working even though I changed one

0

My bad, there are conflicting parts of the code. It's trying to set it to your mouse's position as well as the torso's position.

0

It needs to be one or the other, can't be both.

0

Is there a way to have one side linked to the torso and the other following the mouse or is that impossible?

0

Yeah there's a way.. you could use the CFrame.new(vector origin, vector focus) constructor on the SetPrimaryPartCFrame function. Have the origin be the Torso, and the focus be the Mouse.

This discussion is preserved as it was. New answers, comments, and votes are closed.