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

How do I use Script.Source properly??

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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!

0
Thanks a ton, very helpful! ElectricZooo 55 — 4y
0
Hmm, actually this doesn't do exactly what I want to do, but I still learned something :) ElectricZooo 55 — 4y
Ad

Answer this question