【问题标题】:bad argument #3 to 'Text' (string expected, got nil)'Text' 的错误参数 #3(预期字符串,得到 nil)
【发布时间】:2021-10-09 03:08:24
【问题描述】:

我正在 roblox 中占有一席之地。我写了剧本,看看它,请说它有什么问题??? 在另一个脚本中一切正常!你能帮我吗?

    local players = game.Players:GetChildren()
    local pupil = players[math.random(0,#players)]
    local James = game.Workspace.James
    local Texte = game.StarterGui.ScreenGui.Maintexzt
    local nameq = game.StarterGui.ScreenGui.Maintexzt.Nameq
    function ontouch(hit)
    if hit.Parent:findFirstChild("Humanoid") then
    print("Trigget working!")
    James.Humanoid.Torso.CFrame = game.Workspace.OutOfhere.CFrame
    script.Parent.CFrame = game.Workspace.SpawnLocation.CFrame
end
end
    script.Parent.Touched:Connect(ontouch)
    function ontouchexit()
Texte.Text = "Uh... We did it??"
wait(2)
nameq.Text = players.Name
Texte.Text = "Oh how we make it?"
wait(2)
nameq.Text = James.Name
Texte.Text = "Better, go home!"
wait(3)
nameq.Text = players.Name
Texte.Text = "Go!"
nameq.Text = James.Name
Texte.Text = "But go to my home!"
nameq.Text = players.Name
Texte.Text = "Nope"
nameq.Text = James.Name
Texte.Text = "Your choice, Your die, You can follow me, or not"
end
script.Parent.TouchEnded:Connect(ontouchexit)

请说一下有什么问题,我想完成一个开发的地方。

【问题讨论】:

  • 错误发生在哪一行?
  • 欢迎来到 StackOverflow。请花点时间阅读Help Center - Asking。通过阅读您遇到的错误并进行一些思考,可以轻松避免大多数像您这样的问题。这意味着,如果您需要我们的帮助 - 请将完整的错误消息发送给我们,包括行号和相关代码。

标签: lua roblox


【解决方案1】:

这可能会有所帮助:

local Workspace     =   game.Workspace or workspace;
local StarterGui    =   game.StarterGui;
local players       =   game:GetService("Players");
-----------------------------------------------------------------------------
local Pupil     =   Players[math.random(0,#Players)];
local James     =   Workspace:FindFirstChild("James");
local Texte     =   StarterGui.ScreenGui:FindFirstChild("Maintexzt");
local nameq     =   StarterGui.ScreenGui.Maintexzt:FindFirstChild("Nameq");
local Target    =   ""; --Stores any string value of players that touched the TouchPart
-----------------------------------------------------------------------------
function ontouch(hit)
    if (hit.Parent:FindFirstChild("Humanoid")) then
        print("Trigger working!");
        Target                      =   hit.Parent.Name;    --Saves value of a player's name
        James.Humanoid.Torso.CFrame =   Workspace.OutOfhere.CFrame;
        script.Parent.CFrame        =   Workspace.SpawnLocation.CFrame;
    end
end
-----------------------------------------------------------------------------
function ontouchexit()
    --Replaced 'players.Name' into 'Target', which contains string
    Texte.Text = "Uh... We did it??"
    wait(2)
    nameq.Text = Target
    Texte.Text = "Oh how we make it?"
    wait(2)
    nameq.Text = James.Name
    Texte.Text = "Better, go home!"
    wait(3)
    nameq.Text = Target
    Texte.Text = "Go!"
    nameq.Text = James.Name
    Texte.Text = "But go to my home!"
    nameq.Text = Target
    Texte.Text = "Nope"
    nameq.Text = James.Name
    Texte.Text = "Your choice, Your die, You can follow me, or not"
    Target = ""; --Resets the value of who previously touched the TouchPart
end
-----------------------------------------------------------------------------
script.Parent.Touched:Connect(ontouch)
script.Parent.TouchEnded:Connect(ontouchexit)

编辑:如果不起作用,请尝试更换

function ontouch(hit)
    if (hit.Parent:FindFirstChild("Humanoid")) then

有了这个

function ontouch(hit)
    if (hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name == players.Name) then

这会检查触摸它的人是真正的玩家,而不是来自也有类人生物的人(NPC)

【讨论】:

    【解决方案2】:
    local players = game.Players:GetChildren()
    

    https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren

    返回一个数组(一个数字索引表),其中包含所有 实例的直接子代

    nameq.Text = players.Name
    

    不是 Robolox 专家,我发现 players.Name 不太可能是 nil

    您的代码进一步表明将值分配给这些 Text 属性将调用某些函数。这将向我解释错误消息。

    我不认为很多玩家会说"Uh... We did it??" 所以我想解决你的问题的方法是找出你真正想和谁说话并使用这个名字。

    打印players.Name 并亲自查看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 2020-05-13
      • 1970-01-01
      • 2023-01-04
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多