What do you want to achieve?
I’m making a Dialogue system controlled with RemoteEvents I guess.
What is the issue?
Currently it works but when there’s more than 1 players then it starts to fast-forward.
What solutions have you tried so far? I don’t know how to fix it and I can’t find anything online
Client:
task.spawn(function()
talkRE.OnClientEvent:Connect(function(msg, name)
playerNameText.Text = name
for i = 1, string.len(msg) do
mainText.Text = msg:sub(1, i)
task.wait(0.055)
end
doneTalkingRE:FireServer()
end)
end)
Server:
function talk(msg, name)
replicatedStorage:FindFirstChild("FloorEvents"):FindFirstChild("Talk"):FireAllClients(msg, name)
replicatedStorage:FindFirstChild("FloorEvents"):FindFirstChild("DoneTalking").OnServerEvent:Wait()
end
talk("Oh, um um uh, sure why not thank you", "Miles Edgeworth")
task.wait(2)
talk("BURGERS, BURGERS", "Maya Fey")
If you have any questions please comment them! Have a nice day.
The main problem is the doneTalkingRE:FireServer() part on the local script.
On client, task.wait()'s speed varies depending on the client’s framerate.
Therefore, if a player has a FPS unlocker or is laggy, the time the remote event is fired will desync.
Additionally, since every client playing the message fires the doneTalkingRE event, if two talk() functions are placed side by side, the second talk function may immediately be cancelled due to a laggier client still being on the previous message, firing the event later when the second talk() function is running.
To fix this, it is better to estimate the time it takes for a message to be finished on the server instead of using a remote event to check when it is done on the client.
Try changing your scripts to these:
Client:
task.spawn(function()
talkRE.OnClientEvent:Connect(function(msg, name)
playerNameText.Text = name
for i = 1, string.len(msg) do
mainText.Text = msg:sub(1, i)
task.wait(0.055)
end
end)
end)
New talk Function on Server:
function talk(msg, name)
replicatedStorage:FindFirstChild("FloorEvents"):FindFirstChild("Talk"):FireAllClients(msg, name)
task.wait(0.055*string.len(msg) + 0.3) --0.3 second delay to wait for slightly laggier clients
--you may want to wait a longer period of time on longer messages, as EACH TIME task.wait() is run on a laggier client, there is a slight extra delay.
end