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

A script that can change the contents of another script?

Is this a possible I mean I doubt it but I don't know. Was wondering this because I want various TextButtons to have the ability to change table data by adding to it and removing other data. I figured since I don't know how to script. That scripts interacting with eachother. Changing the data internally of one of them the tables script would be the only way to do this. Sorry for the dumb question.

2 answers

scripts cannot directly change the content of one another. However, they can communicate by using a remote event. If im wrong, please correct me.

1 comment

0

can use bindable events as well

You can do this by using ModuleScripts.

#A little background about ModuleScripts:

Modules are basically tables that can be accessed by saying The following in a local script:

myModule = require(game.ReplicatedStorage.ModuleScript)

The code inside a module script initially looks like this:

module={}

return module

Module is the table that gets returned when you use the require() to get the module script in the first code example. With how our module script looks right now, it's just returning a blank table. (the table named module)

so, let's add stuff to that table. If I was to add a variable called myVar to my table, it would look like this:

module={}
module.myVar = 2
return module

In our main script, we can access and change myVar by doing the following:

myModule = require(game.ReplicatedStorage.ModuleScript)

print(myModule.myVar)
myModule.myVar = 7
print(myModule.myVar)

This prints myVar which is two, makes myVar

You can have anything inside the table... even functions!

Back in our Modulescript, let's create a function to change myVar:

module={}

module.myVar = 2

function module.Add(amount)
        module.myVar = module.myVar + amount
end

return module

Now let's call that function in our main script:

myModule = require(game.ReplicatedStorage.ModuleScript)

print(myModule.myVar)
myModule.Add(100)
print(myModule.myVar)

Now that you have a basic understanding of module scripts #Lets get to answering your question... You want a gui to change the value in a table, so let's create a table inside our module script:

module={}
module.myTable = {}
return module

I'm not sure what you want to do to make the table change, but as an example, I'm going to add the buttons text to the table when a player clicks a button

Write the following in a local script inside the button:

myModule = require(game.ReplicatedStorage.ModuleScript) 
button = script.Parent 

--function for button clicked goes here but I'm lazy 
        table.insert(myModule.myTable, button.Text)
--end function...
        

You can require the module script across multiple scripts allowing any script you want to make changes to the table inside the module script

6 comments

0

format flexing ..... lmao

0

i love formatting

0

dunno if he saw the post if he did and he didnt reply im going to die a bit inside :(

0

oof

0

u put so much effort in it.....

0

i shall give thee an upvote

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