Part that follows player

Hello,
I am an extremely new roblox developer. I just want to learn how to make a part, or in my case, an R6 block rig, follow a player. The reason I want to do this is that I want to make a video trailer for a game, and I need some players to follow me for it.

I have looked at numerous tutorials, but for some reason, none of them have worked for me.

If you could tell me how to do this (assume I know absolutely nothing, because I do), it would really help me and I would appreciate it.

I am using an R6 avatar and the thing I want to follow me is an R6 block rig.

Thanks for reading all this, I just need help.

2 Likes

You can use Path Finding or you can simply use :MoveTo() in the humanoid you want to follow the player.

The way to do this would be:

-- After you found the humanoid of the NPC or the player you want to be followed and the character of the player you want it to follow...

-- FollowedCharacter will be the main player's character thats going to be followed.

FollowedCharacter.HumanoidRootPart:GetPropertyChangedSignal("Position"):Connect(function()
       -- FollowingCharacter will be the player's character thats going to follow
       
       FollowingCharacter.Humanoid:MoveTo(Character.HumanoidRootPart.Position)
end)
2 Likes

Thanks for the quick reply! But where should I put this script? I don’t really know any scripting, sorry.

You can find tutorials on the basics of scripting on the Roblox Developer Hub. Additionally, you can look up tutorials on YouTube.

Yes, I’ve looked up the tutorials and they didn’t work for me. That is why I am asking on this forum.

You can use body objects in the main part of the model.
Here is a short sample of code I have written a while back for my pet follow script.

local NPC = --Your NPC path
local HRP = --Your HumanoidRootPart path

local BodyPosition = Instance.new("BodyPosition", NPC.PrimaryPart)
BodyPosition.MaxForce = Vector3.new(24000, 24000, 24000)

local BodyGyro = Instance.new("BodyGyro", NPC.PrimaryPart)
BodyGyro.MaxTorque = Vector3.new(24000, 24000, 24000)

while wait() do
	BodyPosition.Position = HRP.Position + Vector3.new(2.2, 2.2, 3)
	BodyGyro.CFrame = HRP.CFrame* CFrame.Angles(0, math.rad(5), 0)
end
1 Like

What does it mean by “Your NPC Path”? I do not know anything about Lua.

Your directory to your NPC model which will follow the player?

Oof, sorry, I don’t understand. Please assume I am a person who hasn’t ever touched any type of coding ever.

Oh alright, also make sure you assign the HRP variable too for the character’s HumanoidRootPart.

Just grab the ROBLOX zombie AI, and take out the part that damages you.

2 Likes

Now you’re thinking like a genius.

3 Likes

This is only meant for a really rough example to get a better understanding.

Declaring a variable:

local Part
local ItsMeImAVariableBoiHahhAhahahaha

Declaring a comment:

-- I do absolutley nothing but just to be read by the developers aka you.
-- This will do nothing to the script
--[[
This as well, but instead you can fold me like a folder to hide it away.
--]]

Declaring a path:

local Part = workspace.Part -- im a part in workspace
local Baseplate = workspace.Baseplate -- im the baseplate in workspace
local Player = workspace.cweego -- im you but in workspace, though this would probs error if it didnt know

Making a loop

while true do
-- This code gets repeated forever
wait() -- this stops it from erroring, dont do (while wait() do)
break -- this stops the code from repeating, put it only if neccessary
end

game:GetService("RunService").Heartbeat:Connect(function()
-- This is also kind of a loop but with runservice, and it runs on physics frames
-- you put code here as well
end)

Connections

local Touch = workspace.Part.Touched:Connect(function(Hit)
-- im a connection, if this part gets touched, it detects.
-- anything that touches, including other parts, players, etc.
end)

-- If you dont use the touch anymore, declare it as a variable which i called it "touch"
Touch:Disconnect() -- use only for perm connections/if you dont plan on using it.
-- if its a part with touch however, you can just destroy it
Touch:Destroy() -- will disconnect and destroy the part.

Magnitude

local DistanceFromPart = (workspace.cweego.HumanoidRootPart.Position - workspace.Part.Position).Magnitude

-- warning, variable above might error, use this in command bar while playing instead.

print(DistanceFromPart) -- try it in studio, it should print your distance from the part.

You can learn more using the wiki, its your dictionary use it please.

1 Like

I should have thought of that.

Hmm, I tried putting the paths in, but it still doesn’t work! (The part that follows the player is called Follower.)

local NPC = Workspace.Follower

local HRP = Workspace.cweego.HumanoidRootPart

local BodyPosition = Instance.new("BodyPosition", NPC.PrimaryPart)

BodyPosition.MaxForce = Vector3.new(24000, 24000, 24000)

local BodyGyro = Instance.new("BodyGyro", NPC.PrimaryPart)

BodyGyro.MaxTorque = Vector3.new(24000, 24000, 24000)

while wait() do

BodyPosition.Position = HRP.Position + Vector3.new(2.2, 2.2, 3)

BodyGyro.CFrame = HRP.CFrame* CFrame.Angles(0, math.rad(5), 0)

end

Hello, everyone that tried to help me. I understand that I should have tried to write my own code first. This is what I have written, but for some reason, it isn’t working.

local NPC = game.Workspace.NPC

local humanoid = NPC.Humanoid

while True do

MoveTo(game.Workspace.HeeboKid.HumanoidRootPart)

end

You have a captal on true & theres no wait function which will case an overload & you should do humanoid:MoveTo(workspace:WaitForChild(“your name here”).HumanoidRootPart), if that didnt work try humanoid:MoveTo(workspace:WaitForChild(“your name here”).HumanoidRootPart.Position)