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

How to put code in a newly instanced script?

Asked by 10 years ago

Here is my code..

game.Players.PlayerAdded:connect(function(player)

local Script = Instance.new("Script", game.Workspace)
Script.Name = player.Name

end)

But i need some help, i do not understand how i can write code for the script that will accure in Workspace. I need to put some code inside the script. Can someone help me?

And i also wonder if there is any smarter way to place the script. It does only need to be running for the client and it can not be recreated in death. So not inside the StarterGUI or StarterPack. Please help anyone :-)

2 answers

Log in to vote
2
Answered by
User#2 0
10 years ago

There is no way to do this with a normal or local script, sadly. But there are some work-arounds!

One of the work arounds is to have the script pre-made and then place that script somewhere, anywhere you'd prefer, and then set it's Disabled property to true. When you need the script, clone it and place it where it needs to be, then set it's Disabled property to false.

The other way is to have a script or local script, said script should be Disabled, with the following inside of it:

loadstring(script.Src.Value)()

The script should also have a StringValue, in this case named "Src", inside of it. When you want to use the script, clone it. Then change the StringValue's Value to the source you want to run. After that, place it and set Disabled to false.

Ad
Log in to vote
0
Answered by 10 years ago

There is no way to edit a code of a script outside of Edit mode. I would crate the script, put in the code you want, and make it disabled.

Then use something like;

game.Players.PlayerAdded:connect(function(player)

local ScriptC = script.SCRIPT_NAME:Clone()
ScriptC.Parent = script 
ScriptC.Name = player.Name
ScriptC.Disabled = false
end)

Answer this question