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?
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
use _G like: script1:
_G.variable = "Hi"
script2:
print(_G.variable)
OUTPUT:
[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