Hello, I recently stumbled upon a weird thing using .OnServerEvent:Wait
to simplify, i was making a simple dialog box, but the text seems to be overlapping eachother, so i decided to add .OnServerEvent:Wait and waits for client to fire the remote, each time the dialog is finished, the client will fire it properly.
Video : https://gyazo.com/b0a59118ad4727a78e63cc2da91478ae
Incase you’re wondering of the code :
Server :
local remote = game.ReplicatedStorage:WaitForChild("Prompt")
remote.OnServerEvent:Connect(function()end)
game.Players.PlayerAdded:Connect(function(plr)
task.wait(5)
remote:FireClient(plr,"Hello! lol")
task.wait(2)
remote:FireClient(plr)
remote.OnServerEvent:Wait()
print("passed1")
task.wait(2)
remote:FireClient(plr,"The quick brown fox jumps over the lazy dog")
remote.OnServerEvent:Wait()
print("passed2")
task.wait(2)
remote:FireClient(plr,"yuo reading?")
end)
Client :
local remote = game:GetService("ReplicatedStorage"):WaitForChild("Prompt")
local frame = script.Parent.Parent
local text = script.Parent
local function convert(str)
local result = ""
for word in string.gmatch(str,"%S+") do
result ..= '<font transparency="1">'..word..'</font> '
end
return result
end
local function setTransparency(str,word,value)
for markup in string.gmatch(str,'<font transparency=.->.-</font>') do
local findWord = markup:find(word)
if findWord then
local findTransparency : string = markup:match("<font transparency=.->"..word)
local num = findTransparency:match("<font transparency=(.-)>")
if findTransparency then
str = str:gsub(findTransparency,findTransparency:gsub(num,'"'..value..'"'))
end
return str
else
continue
end
end
end
local ts = game:GetService("TweenService")
local tweenTime = .5
local info = TweenInfo.new(tweenTime)
local prompted = false
local framepos = UDim2.fromScale(0.5,0.048)
local toppos = UDim2.fromScale(0.5,-1)
remote.OnClientEvent:Connect(function(txt)
if (prompted and not txt) or (txt == nil) then
prompted = false
ts:Create(frame,info,{Position = toppos}):Play()
remote:FireServer()
elseif txt then
prompted = true
ts:Create(frame,info,{Position = framepos}):Play()
local converted = convert(txt)
text.Text = converted
for word in converted:gmatch("<font transparency=.->(.-)</font>") do
local iteration = 25
local delayBetweeniterations = .001
for i = 1, iteration do
text.Text = setTransparency(text.Text,word,1-(i/iteration))
task.wait(delayBetweeniterations)
end
task.wait(.01) --delay per word
end
remote:FireServer()
print("Fired")
end
end)
Based on the video, as you can see when remove the connection to remote, it does not wait at all, but when adding a connection to a remote, it works as intended, was this documented in the remote event page?