roblox studio: TextBox.Text 返回""

我正在制作自定义聊天系统,但我面对了这个"bug"。 TextBox 返回的只是"",而不是 nil。 并没有任何错误。即使没有

string.len(script.Parent.Parent.message.Text) > 0

"if" 部分。

    local db = false
    local TextService = game:GetService("TextService")
    script.Parent.MouseButton1Click:Connect(function ()
        local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
        local dn = plr.Character.Humanoid.DisplayName
        local muted = script.Parent.muted.Value
        local mod = script.Parent.moderator.Value
        if db == false and muted == false and string.len(script.Parent.Parent.message.Text) > 0 then
            db = true
            local ts = 16
            local msg = script.Parent.Parent.chat.message0:Clone()
--problem line
            msg.messageContent.Text = TextService:FilterStringAsync(script.Parent.Parent.message.Text, plr.UserId, "2")
            if string.len(script.Parent.Parent.message.Text) > 130 then
                ts = 14
            end
            msg.messageContent.TextSize = ts
--problem ends
            local ps = msg.prefixes
            ps.bot.Visible = false
            local counter = game.ReplicatedStorage.ChatBlockStorage.counter.Value
            msg.Name = "message" .. counter
            msg.actualName.Text = "@" .. plr.Name
            msg.displayName.Text = dn
            msg.icon.Image = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
            msg.icon.ResampleMode = "Default"
            if script.Parent.Parent.message.customIcon.locked.Visible == false then
                msg.icon.Image = "http://www.roblox.com/asset/?id=" .. script.Parent.Parent.message.customIcon.Text
            end
            if msg.Name == "message1" then
                mod = true
            end
            if mod == true then
                ps.mod.Visible = true
            end
            counter += 1
            script.Parent.Parent.message.Text = ""
            wait(game.ReplicatedStorage.ChatBlockStorage.waitTime.Value)
            db = false
        end
    end)

有什么办法可以修复它吗?

原文链接 https://stackoverflow.com/questions/70635617

点赞
stackoverflow用户16015742
stackoverflow用户16015742

在代码的末尾,你写道:

script.Parent.Parent.message.Text = ""

这不可能是原因吗?

2022-01-13 14:34:47
stackoverflow用户18031292
stackoverflow用户18031292

也许你可以用 tostring(msg)?但可能行不通。

tostring("i like beans")

在这里了解更多关于字符串的内容:https://developer.roblox.com/en-us/articles/String

在这里了解更多关于 tostring() 的内容:https://devforum.roblox.com/t/what-does-assert-and-tostring-do/1047653 (我不认识这些人,但我看过它们,它们提供了有效的信息)

祝你好运,我的兄弟。

2022-01-25 19:54:33
stackoverflow用户19471505
stackoverflow用户19471505

使用 FocustLost 事件。点击这里查看 roblox 文档。

示例代码:

script.Parent.FocusLost:Connect(function(enterPressed)
     if enterPressed then
         print("Focus was lost because enter was pressed!")
     end
end)
2022-07-03 11:36:54