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

attempt to index function with 'Position'?

I have this script that simply moves an NPC to another part, but I get the error "attempt to index function with 'Position'?". Humanoid:MoveTo has always worked for me, so I don't understand why it doesn't work here.

Here's the script:

local move = game.Workspace.interior.WashRoom.move
local kuro = game.Workspace.interior.WashRoom.kuro

wait(3)
print("ah scary")
kuro.Humanoid:MoveTo(move.Position)

5 comments

0

Basically what the error is saying is that kuro is a function that has been set AFTER the line 2 was set. Hope that helps.

0

how is that possible? these 6 lines are the only code in the script.

0

Try setting move.Position to a variable and put the variable in parenthesis.

0

okay, ive tried it. The error still persists, but the error is on line 2 (where I put the variable), instead of line 6

0

The problem is Humanoid is not a physical body part. Use HumanoidRootPart instead.

1 answer

a LOOOOOOONG time ago, models had a function called Model:move(position)

it just teleported the root part (or primarypart) of the model to that position

nowadays, that function is called Model:MoveTo(position), but the old function still exists so that old games don't break

however, when you index an instance, it prioritizes properties, functions, and events over children of that instance

you can confirm this for yourself by running this code in the command bar

local model = Instance.new("Model")
local moveTo = Instance.new("Part")
moveTo.Name = "MoveTo"
moveTo.Parent = model
print(model.MoveTo) --> function: 0x000000000000000

so, for example, if you put a part called "Name" in a model, and tried to get it using Model.Name, it wouldn't give you that part, but the actual name of the model

in your case, when you try to get WashRoom.move, it doesn't give you the part you named move, but rather the function move

really, all you have to do to fix the problem is rename "move" to something else

5 comments

0

THANK YOU... i changed it, but now there is another problem. For some reason, MoveTo() doesn't work as it should. What happens to me, is that the NPC doesn't actually move towards the part until I get near the NPC. I don't know why this suddenly started happening, I was testing the same script in different places, and the problem happened there too.

0

I also used an old script I made that had also used the MoveTo() function, and the problem still happens, even though the script had worked before.

0

weird, is StreamingEnabled turned on

0

nope, hold on ill send a video example of whats going on

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