1

我的脚本是:

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 向所有人显示呢?

4

1 回答 1

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-06-08T21:04:04.840 回答