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.
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)
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.
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)