'Text' 函数的第三个参数出现问题了(预期是一个字符串,但得到了 nil)
2019-10-14 7:7:35
收藏:0
阅读:109
评论:2
我正在制作一个 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 = "嗯...我们做到了??"
wait(2)
nameq.Text = players.Name
Texte.Text = "哦,我们到底怎么做到的?"
wait(2)
nameq.Text = James.Name
Texte.Text = "好了,回家吧!"
wait(3)
nameq.Text = players.Name
Texte.Text = "走吧!"
nameq.Text = James.Name
Texte.Text = "去我家吧!"
nameq.Text = players.Name
Texte.Text = "不了"
nameq.Text = James.Name
Texte.Text = "你的选择,你自己承担后果,你可以跟我来,也可以不来"
end
script.Parent.TouchEnded:Connect(ontouchexit)
请帮我看看哪里出了问题,我想要完成地图开发。
点赞
用户13869224
这可以帮助:
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 = ""; --存储任何接触 TouchPart 的玩家的字符串值
-----------------------------------------------------------------------------
function ontouch(hit)
if (hit.Parent:FindFirstChild("Humanoid")) then
print("Trigger working!");
Target = hit.Parent.Name; --保存玩家姓名的值
James.Humanoid.Torso.CFrame = Workspace.OutOfhere.CFrame;
script.Parent.CFrame = Workspace.SpawnLocation.CFrame;
end
end
-----------------------------------------------------------------------------
function ontouchexit()
--将 'players.Name' 替换为存储字符串的 'Target'
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 = ""; --将之前接触 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-08 17:43:45
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

local players = game.Players:GetChildren()使用
GetChildren()函数可以返回一个由Instance直接子元素所组成的数组。https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren
我不是 Roblox 专家,但我认为
players.Name很可能是nil。你的代码进一步证明了给这些
Text属性分配值会调用某个函数,这是我看到的错误消息的原因。我认为一个玩家数组不会说
"Uh... We did it??",所以我猜想解决你的问题的办法是找到你想要说话的实际玩家并使用他们的名称。打印
players.Name并自行了解。