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?
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)