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

How do you make another script "Tell" another script to run something, using a variable?

Asked by 5 years ago

I'm breaking it down to the very basics, I need a script to trigger when someone walks on it, using the touched function.

I then want the script to trigger another script, and then do some code, for example, print what touched the brick. How would I do this?

0
Use remote functions. B_rnz 171 — 5y
0
Do remoke functions transfer variables? Twenty1chickens 4 — 5y
0
also I can't get the script to run, that's my problem. Twenty1chickens 4 — 5y
0
well post the script so we can have a look at it aazkao 787 — 5y
View all comments (3 more)
0
No, don't use remote functions. In your case you'd need to use a Bindable Event. Pojoto 329 — 5y
0
If you need help with Bindable Events I might write up an answer if you want. Pojoto 329 — 5y
0
What pojoto said, remote functions are for client-server communication or vice versa, but in your case you want server-server communiation aazkao 787 — 5y

1 answer

Log in to vote
0
Answered by
JakyeRU 637 Moderation Voter
5 years ago
Edited 5 years ago

Hello. For this you need to use Bindable Events.

Create a BindableEvent in ReplicatedStorage Insert a Script in a Part and write:

--[[
    Fire Event Script
--]]

script.Parent.Touched:Connect(function()
    game.ReplicatedStorage.BindableEvent:Fire("I love cats!!!!")
end)

This script will Fire the text "I love cats!!!!" to the Bindable Event

Now we need an Event Listener to do something when the BindableEvent is fired.

Create a Script in ServerScriptService and write:

--[[
    Event Listener Script
--]]

game.ReplicatedStorage.BindableEvent.Event:Connect(function(variable)
    print(variable)
end)

You can put anything else instead of variable.

EDIT To do it with variables just put your variable instead of "I love cats!!!!" like this.

MyVariable = "Hello"

script.Parent.Touched:Connect(function()
    game.ReplicatedStorage.Event:Fire(MyVariable)
end)
Ad

Answer this question