传送到出生点脚本
2021-4-8 0:27:50
收藏:0
阅读:258
评论:1
有人知道这个脚本有什么问题吗?脚本应该是如果你的时间倍率比你的时间大750倍,那么传送按钮就会变成可见的,这部分是有效的,但是当它到达你点击的位置时停止工作,开发控制台中没有出现任何错误。我认为发生的是在这行代码后事件不会触发,因为我尝试打印之后没有任何东西被打印出来,所以我认为事件没有被触发。当你点击按钮时,文本应该显示3、2、1,然后重新回到原来的样子,并且你会被传送到出生点,如果你移动了你的角色,那么它会重置,文本会回到正常状态,它不会传送你,并且你必须再次点击它并一直保持静止以传送你。此外,pog是一个boolvalue,我把它添加到了玩家中,默认值为false,当你进入时,它的值是存在的。
代码在文本按钮中的本地脚本中,在startergui中有一个screengui:
player = game.Players.LocalPlayer
character = game.Workspace[player.Name]
while true do
wait(1)
if player.leaderstats.Time.Value < player.TimeMulti.Value*750 then
script.Parent.Visible = false
elseif player.leaderstats.Time.Value >= player.TimeMulti.Value*750 then
script.Parent.Visible = true
end
end
local pog = player.pog.Value
script.Parent.MouseButton1Click:Connect(function()
pog = true
while pog == true do
wait (1)
character.Humanoid.Changed:Connect(function()
if character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "Teleport to spawn"
then
script.Parent.Text = "3"
elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "3" then
script.Parent.Text = "2"
elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "2" then
script.Parent.Text = "1"
elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "1" then
character.Torso.CFrame = game.Workspace.Spawn.SpawnLocation.CFrame
script.Parent.Text = "Teleport to spawn"
elseif character.Humanoid.MoveDirection.Magnitude ~= 0 then
script.Parent.Text = "Teleport to spawn"
pog = false
end
end)
end
end)
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 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 代码?

问题
你在 while 循环下连接了按钮,脚本在 while 循环结束前等待,然后才分配按钮点击事件,但是循环永远不会结束,所以没有连接。
解决方法
只需将
.MouseButton1Click和变量pog事件放在 while 循环之前。(将第 12 行及其以下所有内容移动到 while 循环之前)。如果您有任何问题,请随时提问。如果这解决了您的问题,请确保将其标记为答案,以便其他人也能从中受益。
代码
player = game.Players.LocalPlayer character = game.Workspace[player.Name] local pog = player.pog.Value script.Parent.MouseButton1Click:Connect(function() pog = true while pog == true do wait (1) character.Humanoid.Changed:Connect(function() if character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "Teleport to spawn" then script.Parent.Text = "3" elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "3" then script.Parent.Text = "2" elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "2" then script.Parent.Text = "1" elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "1" then character.Torso.CFrame = game.Workspace.Spawn.SpawnLocation.CFrame script.Parent.Text = "Teleport to spawn" elseif character.Humanoid.MoveDirection.Magnitude ~= 0 then script.Parent.Text = "Teleport to spawn" pog = false end end) end end) while true do wait(1) if player.leaderstats.Time.Value < player.TimeMulti.Value*750 then script.Parent.Visible = false elseif player.leaderstats.Time.Value >= player.TimeMulti.Value*750 then script.Parent.Visible = true end end另外,我强烈建议在
.MouseButton1Click函数下使用 repeat 而不是 while 循环。