[英]bad argument #3 to 'Text' (string expected, got nil)
我正在 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)
請說出它有什么問題,我想完成這個地方的開發。
這可以幫助:
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)
local players = game.Players:GetChildren()
https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren
返回一個數組(一個數字索引表),其中包含 Instance 的所有直接子級
nameq.Text = players.Name
不是 Robolox 專家,我發現players.Name
不太可能是nil
您的代碼進一步建議將 vlaues 分配給這些 Text 屬性將調用一些 function。 這將向我解釋錯誤消息。
我不認為很多玩家會說"Uh... We did it??"
所以我想你的問題的解決方案是找出你真正想和誰說話並使用這個名字。
打印players.Name
並親自查看。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.