Answered by
5 years ago Edited 5 years ago
Your code doesn't work because :FireServer()
and :Connect()
are not being used correctly.
:FireServer()
takes a value or expression to pass to the event. In your case, print"Event Has Fired"
runs and prints to the console, but evaluates to nil and is not passed to the event.
:Connect()
takes in a function to be called when the event is fired. For an event where the server is fired, the first argument to the function will be the player, followed by any arguments passed to :FireServer()
This can be done in two ways, the first being with a named function:
1 | function doStuff(player, myText) |
5 | RemoteEvent.OnServerEvent:Connect(doStuff) |
And the second is an anonymous function:
1 | RemoteEvent.OnServerEvent:Connect( function (player, myText) |
Both are functionally identical, but the named function is more readable and allows you to call the function from somwhere other than the event.
You would fire this event from a LocalScript with the following:
1 | RemoteEvent:FireServer(myText) |