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

Why won't my BodyPosition Work?

Hello! I am in the process of making a random model of Navi from The Legend of Zelda. I am making the model follow you using a BodyPosition. I have the BodyPosition in a part in the model named Wing. All the parts are welded and the BodyPosition works and makes the Whole model move to a position. The problem is I am making Navi follow a player but it does not work.

Here is the script I need help with.

function onPlayerEntered(player)
	player.CharacterAdded:connect(function(char)
       while wait() do
           Workspace.Navi.Wing.BodyPosition.Position.char.Head.Position
       end
   end)
end

1 answer

✓ Accepted answer

Nice try, but not quite! First off, you got the syntax for CharacterAdded correct, however not for when the player enters. I edited your code, and take a look at it:

game.Players.PlayerAdded:connect(function(p)
	p.CharacterAdded:connect(function(c)
		spawn(function()
			while wait() do
				workspace.Navi.Wing.BodyPosition.position = c.Head.Position + Vector3.new(0,2,2)
			end
		end)
	end)
end)

Let me explain it step by step:

1.) PlayerAdded Event calls upon anonymous function when a player enters

2.) Next line tells compiler to call upon CharacterAdded function when character spawns in

3.) spawn is a neat little built-in method that deals with coroutines. In a quick summary, it's almost like making another script to handle what you want. This means that you will have one script handling the bodyPosition each time the character spawns. While it's terribly uneffecient, it still works.

4.) while wait() do will obviously constantly loop and set the BodyPosition

5.) I added + Vector3.new(0,2,2) to make the fairy stay near the shoulder area, because if you set it to the heads position; it would be stuck inside the head.

1 comment

0

Thanks! I didn't know how to make it at an offset either so thanks for fine tuning it for me!

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