0

我在 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)

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

4

2 回答 2

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)时,它都会检查

于 2021-10-08T17:43:45.150 回答
0
local players = game.Players:GetChildren()

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

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

nameq.Text = players.Name

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

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

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

打印players.Name并亲自查看。

于 2019-10-14T09:36:52.053 回答