I am aware that one is able to just place a script inside a part and do script.Parent. But I would like to access a model with a script that's not in the model. I thought it could just be done by doing this game.Workspace.[Insert model name].PartName, but it didn't work, could anyone tell me how to do it? Thanks.
✓ ANSWER ACCEPTED
Access a model through script?
2 answers
✓ Accepted answer
You have an unnecessary period before the square brackets. This would error. If you didn't do this, you did in your question.
local part = workspace["Insert model name"].PartName
In Lua, you can only index like var.Name (for example) if the name of the part/model/etc. is a valid variable name.
However, there is another way to index, which is like var["Name"]. This is equivalent to the first example, and works with other characters besides alphanumeric ones. Knowing this, you could do:
game.Workspace["Street Light"].PartName
and it should work.
Hopefully I explained this well enough.
2 comments
0
Thanks, it worked :)
0
You don't have to have game.Workspace, workspace is a global variable defined by roblox that gives the exact same thing.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
What is the name of the model? If it has spaces or non-alphanumerical characters or starts with a number, there is a special syntax that can be used.
The name of the model is Street Light, with a space in between.