为什么这两个代码的输出是"cutting out"

Why is the output of these two codes "cutting out"

两段代码输出有问题。我对可能发生的事情感到困惑。

编辑:我发现函数触发了 14 次,而它本应只触发 10 次。

(脚本中的运行)

SpeechEvent = game:GetService("ReplicatedStorage"):WaitForChild("SpeechEvent")
SpeechEventFinished = game:GetService("ReplicatedStorage"):WaitForChild("SpeechEventFinished")
AnimationEvent = game:GetService("ReplicatedStorage"):WaitForChild("AnimationEvent")
game:GetService("ReplicatedStorage"):WaitForChild("ChapterStart").OnServerEvent:Connect(function()
    print("test")
    wait(1)
    SpeechEvent:FireAllClients("Hello everyone", "Dictator", 0.05, false, nil)
    SpeechEventFinished.onServerEvent:Wait()
    wait(1)
    SpeechEvent:FireAllClients(", dictator speaking.", nil, 0.05, false, nil)
    SpeechEventFinished.onServerEvent:Wait()
    wait(3)
    SpeechEvent:FireAllClients(nil, nil, nil, true, nil)
    wait(0.1)
    AnimationEvent:FireAllClients(1)
    SpeechEvent:FireAllClients("I am here to congratulate you for your victory in the war", "Dictator", 0.05, false, nil)
    SpeechEventFinished.onServerEvent:Wait()
    wait(3)
    SpeechEvent:FireAllClients(nil, nil, nil, true, nil)
    wait(0.1)
    SpeechEvent:FireAllClients("It was a ", "Dictator", 0.05, false, nil)
    SpeechEventFinished.onServerEvent:Wait()
    SpeechEvent:FireAllClients("gruesome ", nil, 0.5, false, nil)
    SpeechEventFinished.onServerEvent:Wait()
    SpeechEvent:FireAllClients("war, one filled with ", nil, 0.05, false, nil)
    SpeechEventFinished.onServerEvent:Wait()
    SpeechEvent:FireAllClients("blood and sorrow, ", nil, 0.5, false, nil)
    SpeechEventFinished.onServerEvent:Wait()
    SpeechEvent:FireAllClients("but you continued with consistency and determination.", nil, 0.05, false, nil)
    wait(3)
    SpeechEvent:FireAllClients(nil, nil, nil, true, nil)
    wait(0.1)
    SpeechEvent:FireAllClients("That is the mindset of a true warrior of Apzazch.", "Dictator", 0.05, false, nil)
    SpeechEventFinished.onServerEvent:Wait()
    wait(1)
    SpeechEvent:FireAllClients(" Well done.", nil, 0.05, false, nil)
    SpeechEventFinished.onServerEvent:Wait()
    wait(3)
    SpeechEvent:FireAllClients(nil, nil, nil, true, nil)
end)

(本地脚本中的运行)

function onFire(text, character, delaychar, textwipe, returndata)
    if character ~= nil then
        textFinal = character .. ": " .. text
    else
        textFinal = text
    end
    if textwipe == false then
        for count = 0, string.len(textFinal), 1 do
            print(string.sub(textFinal, count, count) .. "         " .. count)
            script.Parent.Parent.SpeechBox.Enabled = true
            script.Parent.Parent.SpeechBox.SpeechBox.Text = script.Parent.Parent.SpeechBox.SpeechBox.Text .. string.sub(textFinal, count, count)
            wait(delay)
        end
        game:GetService("ReplicatedStorage"):WaitForChild("SpeechEventFinished"):FireServer(returndata)
    else
        script.Parent.Parent.SpeechBox.SpeechBox.Text = ""
        script.Parent.Parent.SpeechBox.Enabled = false
    end
end

game:GetService("ReplicatedStorage"):WaitForChild("SpeechEvent").onClientEvent:connect(onFire)

桂是这么说的: 独裁者:大家好,独裁者发言 独裁者:我在这里祝贺你在war中取得胜利 独裁者:那是一场可怕的war,充满了鲜血和悲伤,但你坚持不懈,坚定不移。 独裁者:那就是miWell done

当你查看输出时更奇怪

  test
           0
  D         1
  i         2
  c         3
  t         4
  a         5
  t         6
  o         7
  r         8
  :         9
            10
  H         11
  e         12
  l         13
  l         14
  o         15
            16
  e         17
  v         18
  e         19
  r         20
  y         21
  o         22
  n         23
  e         24
           0
  ,         1
            2
  d         3
  i         4
  c         5
  t         6
  a         7
  t         8
  o         9
  r         10
            11
  s         12
  p         13
  e         14
  a         15
  k         16
  i         17
  n         18
  g         19
  .         20
           0
  D         1
  i         2
  c         3
  t         4
  a         5
  t         6
  o         7
  r         8
  :         9
            10
  I         11
            12
  a         13
  m         14
            15
  h         16
  e         17
  r         18
  e         19
            20
  t         21
  o         22
            23
  c         24
  o         25
  n         26
  g         27
  r         28
  a         29
  t         30
  u         31
  l         32
  a         33
  t         34
  e         35
            36
  y         37
  o         38
  u         39
            40
  f         41
  o         42
  r         43
            44
  y         45
  o         46
  u         47
  r         48
            49
  v         50
  i         51
  c         52
  t         53
  o         54
  r         55
  y         56
            57
  i         58
  n         59
            60
  t         61
  h         62
  e         63
            64
  w         65
  a         66
  r         67
           0
  D         1
  i         2
  c         3
  t         4
  a         5
  t         6
  o         7
  r         8
  :         9
            10
  I         11
  t         12
            13
  w         14
  a         15
  s         16
            17
  a         18
            19
           0
  g         1
  r         2
  u         3
  e         4
  s         5
  o         6
  m         7
  e         8
            9
           0
  w         1
  a         2
  r         3
  ,         4
            5
  o         6
  n         7
  e         8
            9
  f         10
  i         11
  l         12
  l         13
  e         14
  d         15
            16
  w         17
  i         18
  t         19
  h         20
            21
           0
  b         1
  l         2
  o         3
  o         4
  d         5
            6
  a         7
  n         8
  d         9
            10
  s         11
  o         12
  r         13
  r         14
  o         15
  w         16
  ,         17
            18
           0
  b         1
  u         2
  t         3
            4
  y         5
  o         6
  u         7
            8
  c         9
  o         10
  n         11
  t         12
  i         13
  n         14
  u         15
  e         16
  d         17
            18
  w         19
  i         20
  t         21
  h         22
            23
  c         24
  o         25
  n         26
  s         27
  i         28
  s         29
  t         30
  e         31
  n         32
  c         33
  y         34
            35
  a         36
  n         37
  d         38
            39
  d         40
  e         41
  t         42
  e         43
  r         44
  m         45
  i         46
  n         47
  a         48
  t         49
  i         50
  o         51
  n         52
  .         53
           0
  D         1
  i         2
  c         3
  t         4
  a         5
  t         6
  o         7
  r         8
  :         9
            10
  T         11
  h         12
  a         13
  t         14
            15
  i         16
  s         17
            18
  t         19
  h         20
  e         21
            22
  m         23
  i         24
           0
           25
            1
           26
  W         2
           27
  e         3
           28
  l         4
           29
  l         5
           30
            6
           31
  d         7
           32
  o         8
           33
  n         9
           34
  e         10
           35
  .         11
           36
           37
           38
           39
           40
           41
           42
           43
           44
           45
           46
           47
           48
           49
           50
           51
           52
           53
           54
           55
           56
           57
           58
           59

有什么办法可以解决这个问题吗?

发送后

SpeechEvent:FireAllClients("but you continued with consistency and determination.", nil, 0.05, false, nil)

您不是在等待完成的活动。在下一行你应该输入

SpeechEventFinished.onServerEvent:Wait()

即使您等待了 3 秒,下次您发送文本时,以下 Wait() 函数将捕获该事件并直接转到下一个语音行,这将干扰正在发送的行还在 playing/displaying.

中间