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

Communicating from Script to Script???

Asked by 5 years ago

I have a script called "End" in a model in workspace. I have a script called "Generate" in server script service. How can I have these two scripts "communicate" with each other so that I can integrate it into my onTouched event in the end script?

2 answers

Log in to vote
3
Answered by 5 years ago
Edited 5 years ago

You could use a BindableEvent, which has the ability for scripts to talk to one another upon event. Here's an example.

local Bindable = Location_Of_Bindable.BindableEvent;

wait(1);

Bindable:Fire("Hello World!") -- Fires the bindable with the argument

And, within a second script.

local Bindable = Location_Of_Bindable.BindableEvent;

Bindable.Event:Connect(function(Str) -- Listens to be fired
    print("Message sent:", Str); -- Prints what was given when executed
end)

The second code should print Message sent: Hello World!

Stuff talked about 1. BindableEvent

Stuff related, but not talked about 2. BindableFunction - Basically uses a function for when called upon. Think of these as remote, but for their respective sides. (Server-To-Server, LocalScript-To-LocalScript (same client only though))

Apologies if this wasn't "high quality", I haven't post an answer in months. Regardless, I hope this helped. :)

If you have any questions, please don't hesitate to ask. :D

0
happy first-post-in-months post royaltoe 5144 — 5y
0
bro, events are bitly harder than require or _g, but you want rep too :\ gloveshun 119 — 5y
0
Don't make idiotic comments, gloveshun. User#29813 0 — 5y
0
^ DeceptiveCaster 3761 — 5y
0
That's awful and sad. :/ You can't post answers w/o someone thinking that's "they're gonna get rep for it". TheeDeathCaster 2368 — 5y
Ad
Log in to vote
1
Answered by
gloveshun 119
5 years ago
Edited 5 years ago

use _G like: script1:

_G.variable = "Hi"

script2:

print(_G.variable)

OUTPUT:

"Hi"

[EDIT] or Modulescript:

local box = {
["Variable1"] = "Var1",
["Variable2"] = "Var2";
}
return box

script:

local Variable_box = require(game.Workspace.ModuleScript)
function printall()
for i, v in pairs(Variable_box) do
    print(v)
end
end


--function
    printall()

output: Var1 Var2

0
i use _G oftentimes gloveshun 119 — 5y
0
G is slow. Module scripts slow you to keep track of variables/ functions between scripts royaltoe 5144 — 5y
0
and if i not want to use _G, i use require() gloveshun 119 — 5y

Answer this question