Took me a moment to realize that you don't need the server to do any text manipulation at all since it will be a waste a time for the server. You should note that anything meaningless like this should be kept on the client.
A typewriter effect can easily be achieved using for-loop.
local text = "This is a sentence."
local textLabel = someDefinedGui.TextLabel
for i = 1, #text do
textLabel.Text = string.sub(text, 1, i)
wait(1)
end
The above adds a new character from the string to textLabel.Text at a 1 second interval.
Wrapping this in a function should be really simple, but all this should be kept on the local script.
#RemoteFunctions
So another useful tool when working with client-server communication is the RemoteFunction. This is used to allow whatever you're communicating to return information back (be it server or the client). Something relevant to your question is that a RemoteFunction will wait or yield until what is requested is completed.
Say we wanted the server to add two numbers together because the player gave some values:
local RS = game:GetService("ReplicatedStorage")
local addNumbers = RS:WaitForChild("RemoteFunction")
function onAddNumbers(player, a, b)
print("waiting for 5 seconds")
wait(5)
return a + b
end
addNumbers.OnServerInvoke = onAddNumbers
In our function onAddNumbers() we have three arguments: The player parameter is required by the OnServerInvoke event since it is the client communicating. It is then followed by parameters a and b (Values passed by client).
Notice that in the function we also have a wait(5)? Well I'm using this to test the yielding of a RemoteFunction.
After waiting, the function will return the sum of a and b to the client.
local RS = game:GetService("ReplicatedStorage")
local addNumbers = RS:WaitForChild("RemoteFunction")
local calculated = addNumbers:InvokeServer(2, 5)
print(calculated)
The variable calculated stores whatever is return by the server after invoking and yield is completed.
We then obviously print it.
If you find the way how binding OnServerInvoke is done with a = you could see why here
The article may be confusing so let me know if you need more of an explanation on that.
###To conclude:
Many use cases for this is wanting the client request the server for some player data. Like from some player DataStore which the server will return a result.
Note that you should be careful when requesting the server for information from the client. You should never trust the client when it's asking for information from the server, so you will need to have the server-side circumvent that. There are a few articles on game protection for that which you could find yourself.
Let me know if I missed anything since this type of question doesn't need to go this far into server-client communication.
4 comments
The typing script is courtesy of RedcommanderV2: https://scriptinghelpers.org/questions/57162/how-do-you-make-text-on-a-surfacescreengui-animate-so-it-looks-like-it-is-typing-itself-out
i have a terrible idea if u wanna hear it
...sure .-.
at the end of the first remote event, send one back to the client from the server, that would then send the second message. its horrible i know but its also amazing.