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

Attempt to index a number value?

I have probably just missed something very obvious but right now, in the middle of the night, I can't figure out why this errors.

height = ((thePart.Position.Y - target.Torso.Position.Y).magnitude) + 60

thePart is already defined as Baseplate and target is a npc dummy.

2 answers

✓ Accepted answer

I'm assuming you want to check the distance of the Y value between the two

height = 60 + thePart.Position.Y - target.Torso.Position.Y

Or if you want the distance between the two

height = ((thePart.Position - target.Torso.Position).magnitude) + 60

The error is because you're calling .magnitude on a number value instead of a Vector3

Further reading.

3 comments

0

oh right thanks, I guess this has to do with magnitude doesn't work with specific Position values as Postion.Y?

0

Magnitude is for calculating the distance between two positions, it wouldn't make sense to work with specific values as you can just do .Y - .Y

0

You should explain more and give sources.

You cannot call the magnitude function on a number because it is inside the Vector3.new array. Therefore

height = ((thePart.Position.Y - target.Torso.Position.Y).magnitude) + 60

should be

height = (thePart.Position.Y - target.Torso.Position.Y) + 60

Or, alternatively, if you're trying to get the distance between the two positions

height = ((thePart.Position - target.Torso.Position).Magnitude) + 60

I suggest you look up the distance formula (Which is ((a1-a2)^2+(b1-b2)^2+(c1-c2)^2)^.5=dist or sqrt((a1-a2)^2+(b1-b2)^2+(c1-c2)^2)=dist) to check your understanding.

Presuming you just want the height, I would go with the first solution.

Sources: Magnitude, Distance formula

9 comments

0

You downvoted my post because I didn't give a source even though it's the correct answer and explains why...

0

You told him why, you didn't explain it. Yes, you didn't give sources. Thanks for guessing that it was me. Anyways, I recommend that you read this, as it explains how you should answer problems, properly: https://scriptinghelpers.org/help/how-post-good-questions-answers

0

I explained why and answered a follow up question which is everything that the link you just posted says... Furthermore you provided an answer which was the same as my accepted answer instead of suggesting an edit which is what the link you posted says to do...

0

Once again, you did absolutely no explaining. Your answer didn't exist when I started to type mine, I hadn't the chance to suggest an edit.

0

"The error is because you're calling .magnitude on a number value instead of a Vector3" No explaining? Also my answer was accepted before yours was even posted... You can check to see if someone else has answered while/before you answer...

0

Yes, that is stating the problem, not explaining why it was wrong. Yes, mine was posted afterwards, I said that.

0

"You cannot call the magnitude function on a number because it is inside the Vector3.new array." Apart from being wrong this explanation is the same as what I said. (Vector3 is an object and not an array)

0

I said Vector3.new, and go to studio and print out Vector3. "table: 23086268" Anyways, I've no need to continue this.

0

Vector3 is a UserData and is handled as such in Lua. "All Roblox objects and events are userdatas." Further reading: http://wiki.roblox.com/index.php?title=Userdata http://wiki.roblox.com/index.php?title=Vector3 anyway, I guess that's enough arguing.

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