【问题标题】:How can I make changing a text label show to everyone?如何使更改文本标签显示给所有人?
【发布时间】:2021-08-25 21:09:21
【问题描述】:

我的脚本是:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    script.Parent.ClickDetector.MaxActivationDistance = 0
    script.Parent.BrickColor = BrickColor.new("Really red")
    
    local mapfolder = game.Lighting.Folder
    local maps = mapfolder:GetChildren()
    
    chosenmap = maps[math.random(1, #maps)]
    mapclone = chosenmap:Clone()
    local label = plr.PlayerGui.ScreenGui.Frame.TextLabel
    
    if chosenmap.Name == "Blue" then
        label.Text = "A wild Blue Exists!"
    elseif chosenmap.Name == "Yellow" then
        label.Text = "A wild Yellow Exists!"
    elseif chosenmap.Name == "Red" then
        label.Text = "A wild Red Exists!"
    else label.Text = "not ready yet"
    end
    
    mapclone.Parent = workspace
    wait(10)
    mapclone:Destroy()
    script.Parent.BrickColor = BrickColor.new("Lime green")
    script.Parent.ClickDetector.MaxActivationDistance = 32
end)

这很好用,但是当我在与人一起在服务器上测试它时,它不会向他们显示,那么我怎样才能让 TextLabel 向所有人显示呢?

【问题讨论】:

    标签: lua roblox textlabel


    【解决方案1】:

    您只是为本地播放器更新 GUI。您需要遍历所有连接的玩家,然后更新他们的 GUI。 https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayers

    Players = game:GetService("Players")
    for i, player in pairs(Players:GetPlayers()) do
        local label = player.PlayerGui.ScreenGui.Frame.TextLabel
        
        if chosenmap.Name == "Blue" then
            label.Text = "A wild Blue Exists!"
        elseif chosenmap.Name == "Yellow" then
            label.Text = "A wild Yellow Exists!"
        elseif chosenmap.Name == "Red" then
            label.Text = "A wild Red Exists!"
        else label.Text = "not ready yet"
        end
    end
    

    game 可能被认为是全局的,所以我怀疑您是否需要将它作为函数参数传递

    script.Parent.ClickDetector.MouseClick:Connect(function(game)
    

    但是,我敢肯定你不需要plr,因为你不只是使用本地播放器。

    【讨论】:

      猜你喜欢
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多