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

How do the object follow me?

How do object follows me? please help me...

1 comment

0

like a machine that following me

1 answer

✓ Accepted answer

Hi!

Remember that this is not a request site, but I can still take you through how the process is done.

Firstly, the best place for this script to go is in StarterCharacterScripts (this is inside StarterPlayer). This means the script will automatically go inside the player's character once they join the game.

Now, considering it is a child of the player's character, we need to identify where the object is going to follow. I recommend it to follow the HumanoidRootPart. It is basically the same thing as the Torso, but R15 characters don't have a child called "Torso", there is only UpperTorso and LowerTorso.

local torso = script.Parent.HumanoidRootPart

Now it is time to create the object that will follow the player using Instance.new. We can then set its properties to our liking.

local center = Instance.new("Part") --Creates a new Instance, the BasePart.
	center.CanCollide = false --CanCollide is set to false, meaning you can walk through it.
	center.Size = Vector3.new(1,1,1) --Set the size of the object here.
	center.Parent = script.Parent --Set its parent as the player.

Nextly we need to add a BodyPosition. This is a BodyMover that applies a force to the specified object to a position in world coordinates. For this, we can make it apply a force to the character.

local bp = Instance.new("BodyPosition") --Creates a new Instance, the BodyPosition.
	bp.maxForce = Vector3.new(9e+100, 9e+100, 9e+100) --The maximum force it can apply to the part.
	bp.P = 40000 --How much force it will apply to get to the destination. The higher, the faster.
	bp.Parent = center --Set its parent to the moving object.

Now it is time to create the loop that will get the object to follow the player! We can set the BodyPosition's goal to the player's torso now, so the object will follow the player.

while torso.Parent do --While the player's HumanoidRootPart exists
	center.BodyPosition.position = torso.Position --Set the BodyPosition's goal position to the torso.
	wait()
end

center:Remove() --If the loop breaks, that means the HumanoidRootPart no longer exists, thus removing the object.

And that's it! You now have an object that follows the player. Here is the raw code. Make sure this is set in StarterCharacterScripts (located inside StarterPlayer).

local torso = script.Parent.HumanoidRootPart

local center = Instance.new("Part")
	center.CanCollide = false
	center.Size = Vector3.new(1,1,1)
	center.Parent = game.Workspace
local bp = Instance.new("BodyPosition")
	bp.maxForce = Vector3.new(9e+100, 9e+100, 9e+100)
	bp.P = 40000
	bp.Parent = center
	
while torso.Parent do
	center.BodyPosition.position = torso.Position
	wait()
end

center:Remove()

4 comments

0

umm i need u broh xD

0

umm how can i change the part that u give to me?

0

what about the Phatfinding thing?

0

umm sir

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