如何使更改文本标签对每个人都显示?

我的脚本是:

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 = "一只野生的蓝色存在!"
    elseif chosenmap.Name == "Yellow" then
        label.Text = "一只野生的黄色存在!"
    elseif chosenmap.Name == "Red" then
        label.Text = "一只野生的红色存在!"
    else label.Text = "尚未准备好"
    end

    mapclone.Parent = workspace
    wait(10)
    mapclone:Destroy()
    script.Parent.BrickColor = BrickColor.new("Lime green")
    script.Parent.ClickDetector.MaxActivationDistance = 32
end)

这个脚本很好用,但是在我和其他人一起测试的服务器上,它并没有显示给其他人,那么我该如何使得文本标签对每个人都显示呢?

点赞
用户3342050
用户3342050

你只是为本地玩家更新 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 = "一个蓝色野生存在!"
    elseif chosenmap.Name == "Yellow" then
        label.Text = "一个黄色野生存在!"
    elseif chosenmap.Name == "Red" then
        label.Text = "一个红色野生存在!"
    else label.Text = "尚未准备好"
    end
end

game 可能被认为是一个全局变量,所以我怀疑你不需要将它作为函数参数传递进去

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

然而,我确信你不需要 plr 在那里,因为你不仅使用本地玩家。

2021-06-08 21:04:04