如何让更改文本标签显示给所有人?
How can I make changing a text label show to everyone?
我的脚本是:
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 向所有人显示?
您只是在更新本地播放器的 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
,因为您不只是在使用本地播放器。
我的脚本是:
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 向所有人显示?
您只是在更新本地播放器的 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
,因为您不只是在使用本地播放器。