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

A script that can change the contents of another script?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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

0
can use bindable events as well royaltoe 5144 — 4y
Ad
Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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

0
format flexing ..... lmao EmbeddedHorror 299 — 4y
0
i love formatting royaltoe 5144 — 4y
0
dunno if he saw the post if he did and he didnt reply im going to die a bit inside :( royaltoe 5144 — 4y
0
oof EmbeddedHorror 299 — 4y
View all comments (2 more)
0
u put so much effort in it..... EmbeddedHorror 299 — 4y
0
i shall give thee an upvote EmbeddedHorror 299 — 4y

Answer this question