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

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

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

4 comments

0

Don't do that. Roblox studio will crash.

0

Do you have a pre-written script that has code that you want on the new script?

0

And yes i do i just want to instance the script then write in it in the same script.. is it possible?

0

The "Source" can only be accessed in the command bar or in a plugin environment, all other access is blocked for good reasons.

1 answer

✓ Accepted answer

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.

4 comments

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

0

Can't you just put the script in server script service and clone it?

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

0

Ok

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