Roblox Lua 开发

我正在尝试制作一个 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 编程

点赞
用户1296374
用户1296374

如果你怀疑自己的脚本有问题,可以检查一下输出面板。在这个例子中,输出信息如下:

19:02:05.822 - Players.x.PlayerGui.ScreenGui.Frame.TextLabel.LocalScript:1: Expected '(', '{' or <string>, got ':'

这意味着在不应该有冒号的地方出现了冒号。这一行应该改为:

game.Workspace.text:GetPropertyChangedSignal("Value"):Connect(function()
2020-05-20 23:06:34
用户13825230
用户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
用户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