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

[Loadstring] Why did I get this, and how can I use it?

Asked by 7 years ago

Hey all.

I just discovered loadstrings and experimented a little. I was puzzled when I saw these results.

location = loadstring(script.Parent:GetFullName())
test = loadstring("b = 5")
print(location,test)

Here's my result:

nil function: 369C82A8

When I ran it without the test variable, it returned nil - Which is probably the same with the test variable. what I expected was workspace.Part for location and 5 for test.

Can someone please clarify loadstrings for me?

Thanks

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You recieved that output due to the fact that loadstring returns a function. You still have to call this function in order to play your code. What you did was created the function to call, and then printed it.

Try it this way;

loadstring("test = 5")()
loadstring("location = script.Parent:GetFullName()")()

print(test,location)
0
Are the empty brackets Necessary? fahmisack123 385 — 7y
1
Firstly, they are parenthasis - brackets look like this: []. Secondly, yes. That is how you call functions. Goulstem 8144 — 7y
0
Since loadstring is returning a function, you call it again. Goulstem 8144 — 7y
Ad

Answer this question