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

Can I make this work? // MoveTo("String".Position) // ERROR -> is not a valid member of Model

Hello! And thank you for your interest in my question. I'm starting to learn lua and I came across this problem.

I want a humanoid to move to one of 4 bricks, choosing it's destination at random. The error I'm facing is "str1 is not a valid member of Model". I think I have an idea of why I came across this error, is there any way around it?

If you have a better suggestion on how I can do this, please share!

whereTo = game.Workspace.test2.possibleDestination
walker = game.Workspace.test2.Walker2.Humanoid
--inside "whereTo" I have a  few bricks named "way1" "way2" "way3" "way4"

position = math.random(4)
str0 = (".way" .. position)
str1 = (tostring(whereTo) .. str0)
walker:MoveTo(str1.Position)

Thank you for your time :-)

1 answer

✓ Accepted answer

A string is just an array of characters. They do not point to a physical object. If you want to get a random way part inside whereTo then you index whereTo itself.

walker:MoveTo(whereTo["way"..math.random(4)].Position)

1 comment

0

This works! Thank you

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