用户加入后消息有时候不显示

我制作了一个聊天模块,当用户加入聊天时它会在聊天中显示一条本地消息,但有时候当他们加入时消息不会出现,但有时候消息会出现。我想这是因为玩家加载得不够快吗?是否可以在运行消息的代码之前等待玩家完全加载?我知道你可以在玩家加入之前等待一些代码运行,但我不知道如何在模块脚本中实现这一点(我尝试过了)。这是我的脚本:

local function Run(ChatService)

local server = ChatService:AddSpeaker("Server")
server:JoinChannel("All")
local local_nick = nil

ChatService:GetChannel("All").SpeakerJoined:connect(function(speaker)
        spawn(function()
            server:SayMessage(string.format("你好 %s,欢迎来到百练的F3X建筑场!",speaker),"All")
            server:SetExtraData("NameColor", Color3.new(
            150.0/255.0,
            167.0/255.0,
            255.0/255.0)
            )
            server:SetExtraData("ChatColor", Color3.new(
            249.0/255.0,
            207.0/255.0,
            249.0/255.0
            ))
        end)
    end)
end
return Run
点赞
用户88888888
用户88888888

尝试使用新的 roblox setCore() 函数,只能在 localscripts 中工作。以下是代码

game.Players.PlayerAdded:connect(function(plr)
wait() -- 有时需要等待
game.StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "欢迎来到我的游戏!"; -- 必填. 必须为字符串!
Color = Color3.new(0, 1, 1); -- 青色是 (0, 255 / 255, 255 / 255). 可选,默认为白色:Color3.new(255 / 255, 255 / 255, 243 / 255)
Font = Enum.Font.SourceSans; -- 可选,默认为 Enum.Font.SourceSansBold
FontSize = Enum.FontSize.Size24; -- 可选,默认为 Enum.FontSize.Size18
})

end)

希望这会有所帮助,如果不行,请确保将 localscript 放置在 Starter Player -> StarterPlayerScripts 中。

2017-11-02 08:09:41