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

Attempt to index a number value?

Asked by
Kryddan 261 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by
DevSean 270 Moderation Voter
8 years ago

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.

0
oh right thanks, I guess this has to do with magnitude doesn't work with specific Position values as Postion.Y? Kryddan 261 — 8y
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 DevSean 270 — 8y
0
You should explain more and give sources. drahsid5 250 — 8y
Ad
Log in to vote
-1
Answered by
drahsid5 250 Moderation Voter
8 years ago

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

0
You downvoted my post because I didn't give a source even though it's the correct answer and explains why... DevSean 270 — 8y
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 drahsid5 250 — 8y
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... DevSean 270 — 8y
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. drahsid5 250 — 8y
View all comments (5 more)
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... DevSean 270 — 8y
0
Yes, that is stating the problem, not explaining why it was wrong. Yes, mine was posted afterwards, I said that. drahsid5 250 — 8y
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) DevSean 270 — 8y
0
I said Vector3.new, and go to studio and print out Vector3. "table: 23086268" Anyways, I've no need to continue this. drahsid5 250 — 8y
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. DevSean 270 — 8y

Answer this question