Roblox Lua 开发
2020-5-20 17:12:12
收藏:0
阅读:185
评论:3
我正在尝试制作一个 Roblox 游戏, 但是当我用 lua 脚本编写代码时,当我触摸门时什么也没有发生: 用于文本标签的开始 GUI
game.Workspace.text:GetPropertyChangedSignal("Value"):Connect:(function())
local text = script.Parent
if game.Workspace.text.Value == 1 then
script.Parent.Parent.Visible = true
text.Text = "W"
wait (.05)
text.Text = "We"
wait (.05)
text.Text = "Wel"
wait (.05)
text.Text = "Welc"
wait (.05)
text.Text = "Welco"
wait (.05)
text.Text = "Welcom"
wait (.05)
text.Text = "Welcome"
wait (.05)
text.Text = "Welcome !"
wait (.05)
wait (3)
text.Text = "C"
wait (.05)
text.Text = "Co"
wait (.05)
text.Text = "Come"
wait (.05)
text.Text = "Come I"
wait (.05)
text.Text = "Come In "
wait (.05)
text.Text = "Come In !"
wait (.05)
wait (3)
script.Parent.Parent.Visible = false
end
end)
门的代码:
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.Workspace.text.Value = 1
end
end)
感谢您的答案,我从未使用过 lua 编程
点赞
用户13825230
好的,这里有一些问题,但我愿意帮助你!我会向你展示如何正确地动画化文本并高效地进行操作!
首先,您可能尝试从服务器端脚本编写 UI。在 Roblox 中使用图形用户界面时,请确保使用 LocalScript 编写 Gui,以便它位于客户端。如果要更改所有客户端的 UI,则可以使用称为“RemoteEvent”的东西,稍后详细说明。
我将提供开源代码,并解释(如果您想要的话)。
以下是您需要的一些内容:
- 在 ReplicatedStorage 内部的 “RemoteEvent”(命名为:DoorEvent)
- 在 StarterGui 内的 “ScreenGui”
- ScreenGui 中的 TextLabel(按您的喜好自定义)
现在,在 ServerScriptService 中插入一个常规脚本(“仅用于防止利用”)。
这是门的脚本:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DoorEvent = ReplicatedStorage:WaitForChild("DoorEvent")
local door = workspace:FindFirstChild("NAME OF DOOR HERE")
door.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
local player = game:GetService("Players"):FindFirstChild(hit.Parent.Name)
if plr then
DoorEvent:FireClient(plr)
end
end
end
end)
基本上,使用触摸事件来发出远程事件,我们使用它是因为有一个称为 FilteringEnabled(开发者防御)的属性。
现在继续在 TextLabel 中插入一个 LocalScript,并插入以下代码。(别担心,它可能看起来很混乱,如果您需要,请要求澄清)
代码:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DoorEvent = ReplicatedStorage:WaitForChild("DoorEvent")
local TextLabel = script.Parent
local text
local function animateText(word)
text = word
for char = 1, #text do
TextLabel.Text = string.sub(text,1,char)
wait(.05)
end
end
animateText("这是一个示例句子,您可以在字符串中放置任何东西。")
wait(2.5)
animateText("您可以尽可能多次重复此操作")
- 如果要在完成后摆脱文本,则可以将其缓动或仅切换可见性)
2020-06-27 17:19:41
用户15404375
将下面翻译成中文并且保留原本的 Markdown 格式,
Incorrect statement on the `game.Workspace.text:GetPropertyChangedSignal("Value"):Connect:(function())`
do this for that line instead :
`game.Workspace.text:GetPropertyChangedSignal("Value"):Connect(function())`
针对这个行错误声明而言,正确的方式应该是:
game.Workspace.text:GetPropertyChangedSignal("Value"):Connect(function())
2021-03-16 01:45:06
评论区的留言会收到邮件通知哦~
推荐文章
- 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 代码?

如果你怀疑自己的脚本有问题,可以检查一下输出面板。在这个例子中,输出信息如下:
19:02:05.822 - Players.x.PlayerGui.ScreenGui.Frame.TextLabel.LocalScript:1: Expected '(', '{' or <string>, got ':'这意味着在不应该有冒号的地方出现了冒号。这一行应该改为:
game.Workspace.text:GetPropertyChangedSignal("Value"):Connect(function()