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

How do I use Script.Source properly??

I'm creating a Plugin for roblox studio that writes a simple script and puts it in ServerScriptStorage. However, I'm having trouble getting it to work the way I want it too. This is what I have so far...

Script.Source = [====[ local ["game.Workspce.Part.Name"] = game.Workspace.Part
	print("Done")
	]====]

and when I use the plugin the output in ServerScriptStorage is this...

local ["game.Workspace.Part.Name"] = game.Workspace.Part
print("Done")

but I want ["game.Workspace.Part.Name"] to be the acually name of the part like this...

local PartName = game.Workspace.Part
print("Done")

Is there a way I can make ["game.Workspace.Part.Name"] not be read as a string?

1 answer

✓ Accepted answer

I wouldn't recommend doing this, because dynamically naming variables like this can easily cause problems, however you could do this using getfenv() like so:

getfenv()[workspace.Part.Name] = workspace.Part
print(Part) --> Part

which would define a variable within the function environment that has the same name as the part (in this case, 'Part')

If you found this answer helpful be sure to mark as an answer and upvote!

2 comments

0

Thanks a ton, very helpful!

0

Hmm, actually this doesn't do exactly what I want to do, but I still learned something :)

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