Roblox Lua 开发

Roblox Lua Developpement

我正在尝试制作 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

中编码

如果您怀疑您的某个脚本可能有问题,请检查您的输出窗格。在这种情况下,它表示:

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

这意味着在不应该有的地方有一个冒号。该行需要是:

game.Workspace.text:GetPropertyChangedSignal("Value"):Connect(function()

嗯,这里有一些问题,但我愿意帮助你!我将向您展示如何正确有效地为文本设置动画!

首先,您可能尝试从服务器端脚本编写 UI 脚本。在 Roblox 上使用图形用户界面时,请确保使用 LocalScript 对 Guis 进行编码,以便它是客户端。如果你想为所有客户端更改 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)

基本上这只是使用触摸事件来触发 RemoteEvent,我们使用它是因为 属性 称为 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("This is an example sentence, put whatever you want here as a string.")
wait(2.5)
animateText("You can repeat this as many times as you wish")

--If you want to get rid of the text when it's done you can either tween it or simply toggle the visibility)

game.Workspace.text:GetPropertyChangedSignal("Value"):Connect:(function())

语句不正确

为该行执行此操作: game.Workspace.text:GetPropertyChangedSignal("值"):连接(函数())