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

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

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?

7 comments

0

Use remote functions.

0

Do remoke functions transfer variables?

0

also I can't get the script to run, that's my problem.

0

well post the script so we can have a look at it

0

No, don't use remote functions. In your case you'd need to use a Bindable Event.

0

If you need help with Bindable Events I might write up an answer if you want.

0

What pojoto said, remote functions are for client-server communication or vice versa, but in your case you want server-server communiation

1 answer

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)

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