Lonnie Best
Lonnie Best

Reputation: 11354

Scripting Character Movement in Roblox

I'm trying to help a beginner who has persistent aspirations of creating a game using Roblox Studio. Given the things he wants to do, I told him that the first thing he needs to figure out is how to move a character that's inside the models he has been creating.

I attempted to help him make a character move based on this article. We created a new game map that only has two things on it:

  1. A dummy humanoid
  2. A US Flag

Then we added this script to the workspace:

local dummy = game.Workspace.Dummy.Humanoid
local flag = game.Workspace.USAnimatedFlag.PrimaryPart.Position
dummy:MoveTo(flag)

Each time we build and run this little world, the dummy doesn't move at all. Then when we go look at the output we see this error:

Workspace.Script:2: attempt to index nil with 'Position'

We're trying to achieve movement of this dummy. We'd appreciate any suggestion that would accomplish moving the dummy ANYWHERE, because no matter what we try, we can't get it to move at all.

Upvotes: 0

Views: 2156

Answers (2)

Kylaaa
Kylaaa

Reputation: 7188

A few people were experiencing this problem on the DevForums as well. The solution there was to check that there aren't any anchored parts.

When I tried to replicate your issue using the RigBuilder plugin, the HumanoidRootPart was anchored, and that prevented the model from moving. When I unanchored it, the model started moving, but no animations played. But that's a different issue.

local humanoid = game.Workspace.Dummy.Humanoid

humanoid.MoveToFinished:Connect(function(reached)
    print("Done moving : ", reached)
end)

humanoid:MoveTo(Vector3.new(10, 5, 10))

enter image description here

Upvotes: 1

wetturtle45
wetturtle45

Reputation: 3

The primary part not be set as it refers to it as nil.

Upvotes: 0

Related Questions