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

How to change code in a script from another script?

So, i was wanting to know like i have a script and it has code in it, but how do i change the code in that script with another one? I don't really know how else to explain.

7 comments

0

Why is everyone making a script builder now?

0

Your answer is : YOU DON'T OK???? Unless you have lvl 5 or lvl 6 script.

0

There is ABSOLUTELY no need to do this. If you need to dynamically create and run code(command line GUI), Enable LoadString but this puts you at a huge security risk

0

But that doesnt change the code in a script. It just changes what it does.

0

Thats not what i asked

0

Well thats your only option

0

You could put a StringValue as the child of one script and loadstring that StringValue with the original script, and make modifications with the StringValue in a second script. It's very inefficient though you'd be better off using BindableEvents

2 answers

Short answer - you can't. The script needs to have the permission level of a plugin or higher to change the source of a script.

But, you can accomplish roughly the same thing with loadstring() (this is assuming you are wanting to make a script builder - note to those in the comments, maybe you should ask what they are trying to do first?)

Here's an example:

-->> Trys to execute what someone says as code every time they speak

Player.Chatted:Connect(function(Message)
	loadstring(Message)
end)

Make sure loadstring is enabled, or it won't work.


Hope I helped!

~TDP

3 comments

0

How do i enable loadstring?

0

How do i enable loadstring?

0

LoadString is under ServerScriptStorage. Before you do this tho, remember that LoadString makes ANYTHING possible with even a basic hack, and there is no way to stop that. Your game will most likely never go ANYWHERE with LoadString. Find other ways to do what you want to do with things such as if statements.

Well, what I would do is keep a script in Lighting or ServerStorage and clone it fo when you need it.

EX;

script.Parent.TouchEnded:connect(function()

local a = game.Lighting:findFirstChild("Script name"):Clone()
	a.Parent = game.Workspace:findFirstChild("Insert Model Here")

end)

Or you could simply just have a script disabled and enable it when something happens

EX;

script.Parent.TouchEnded:connect(function()

game.Workspace.[insert model].[script name].Enabled = true

end)

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