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

How do I use string values in paths?

Asked by 10 years ago

I'm working on a gun that makes different GUI outcomes happen when I kill other players. The way I want the script to work seems pretty simple: I have every potential GUI outcome in the PlayerGui, so I put every ScreenGUI name in a table, and give a variable a random value from that table. What I don't know is how to use that string value in a path. Ideally the path would be game.Players.LocalPlayer.PlayerGui.<random string value here>.LocalScript. I would enable the script and make the outcome happen, but I don't know how to put that string value in the path. Is it possible?

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

I find the loadstring solution to be very poor. Any eval-like function is inherently dangerous and shouldn't ever be used as a crutch -- in cases like this there are definitely ways to avoid using it, and you should.

In this Question I give a full solution to parsing Lua paths

Please note that that solution is fairly long and also probably very overpowered for your needs here. See below.


However, since you've already acknowledged that there's a particular format you'd like, you could just use that instead.

If the only thing that is different is that <random string value here> you can just use:

game.Players.LocalPlayer.PlayerGui[someString].LocalScript

Where someString is the string of that name in that location.

In addition to avoiding loadstring, this sort of organization will be simpler and much easier to understand.

Perhaps I didn't quite grasp the hierarchy you imagined, but a solution like the previous would be far superior to loadstring for something so easily accomplishable.

Ad
Log in to vote
-1
Answered by
Bebee2 195
10 years ago

Frankly, it is possible in LocalScripts (if my memory serves right). In server scripts, you have to enable LoadString which Admins will frown at.

-- LocalScript

pathname = 'workspace.Bebee2'
loadstring('return '..pathname)().Head:destroy()

Otherwise, you SHOULD use an ObjectValue.

0
Thank you this is what I needed. What's the issue with LoadString though? Was there some exploit related to it? sergiu8957 5 — 10y
0
If you enable LoadString for SERVER SCRIPTS, then hackers could do server stoof with local access. Bebee2 195 — 10y
0
It's because of bad people we can't have nice things )-; M39a9am3R 3210 — 10y
0
This is a poor solution for several reasons (complexity, security) BlueTaslem 18071 — 10y

Answer this question