Hello. For this you need to use Bindable Events.
Create a BindableEvent in ReplicatedStorage
Insert a Script in a Part and write:
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:
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)
7 comments
Use remote functions.
Do remoke functions transfer variables?
also I can't get the script to run, that's my problem.
well post the script so we can have a look at it
No, don't use remote functions. In your case you'd need to use a Bindable Event.
If you need help with Bindable Events I might write up an answer if you want.
What pojoto said, remote functions are for client-server communication or vice versa, but in your case you want server-server communiation