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

How would i instance a script then write code in it with one script?

Asked by 6 years ago

To be honest this is starting to get to me.. lol

I don't need my question getting deleted so i'll write a code attempt if anyone could answer this question it would help alot

Instance.new("Script",game.Workspace).Source="print(\"Hello World! v2\")"

note this isn't mine this is a script i found when trying to figure this question out

0
Don't do that. Roblox studio will crash. hiimgoodpack 2009 — 6y
0
Do you have a pre-written script that has code that you want on the new script? rilgundam 65 — 6y
0
And yes i do i just want to instance the script then write in it in the same script.. is it possible? Cmonlol135 5 — 6y
0
The "Source" can only be accessed in the command bar or in a plugin environment, all other access is blocked for good reasons. User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Sources cannot be set with a script, however, you can with command bar or studio property panel. What I am assuming what you want done, is to run a custom string in Lua. For that, we will need loadstring. For example, you could make a remote event and a client fires it.

game.ReplicatedStorage:WaitForChild('SentCode' --[[or the remote name]]).OnServerEvent:Connect(function(plr, code)
    pcall(function()
        loadstring(code)() --MAKE SURE YOU DON'T FORGET THE TWO PARENTHESIS AT THE END, I DO NOT KNOW WHY YOU NEED THEM BUT WITHOUT THEM THE CODE DOES NOT RUN.
    end)
end)

If you are trying to do something else, please put a comment and tell me what u want to happen.

0
Ok the reason i want it instanced is because im making a new script for void and i was wondering is it possible to instance a script then write the code afterwards Cmonlol135 5 — 6y
0
Can't you just put the script in server script service and clone it? rilgundam 65 — 6y
0
meh it isn't what i wanted.. but if this was a different situation it would be correct.. thanks for the help ima rate 1 Cmonlol135 5 — 6y
0
Ok rilgundam 65 — 6y
Ad

Answer this question