Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't my BodyPosition Work?

Asked by 9 years ago

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

Log in to vote
2
Answered by 9 years ago

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.

0
Thanks! I didn't know how to make it at an offset either so thanks for fine tuning it for me! minikitkat 687 — 9y
Ad

Answer this question