Hello friends,
I am trying to make a server script, that will repeat wait until there are at least 2 players. The script is not working. Once there are 2 players in game, the text label is not changing it’s text.
local Players = game:GetService("Players")
repeat wait()
until game.Players.NumPlayers >= 0
for i, player in pairs(Players:GetPlayers()) do
player.PlayerGui.ScreenGui.TextLabel.Text = "Starting game..."
end
local Players = game:GetService("Players")
task.wait(7)
for i, player in pairs(Players:GetPlayers()) do
player.PlayerGui:FindFirstChild("ScreenGui"):FindFirstChild("TextLabel").Text = "Starting game..."
end
If you want this to run only when there are enough players, do this:
local Players = game:GetService("Players")
local RequiredToPlay = 2
Players.PlayerAdded:Connect(function(Player)
if #Players:GetPlayers() >= RequiredToPlay then
--code here
end
end)
Or you could make a function to do that each time you want, depends on your needs.
The second script is not working for some reason. Here is the code i used.
local Players = game:GetService("Players")
local RequiredToPlay = 2
Players.PlayerAdded:Connect(function(Player)
if #Players:GetPlayers() >= RequiredToPlay then
for i, player in pairs(Players:GetPlayers()) do
player.PlayerGui:FindFirstChild("ScreenGui"):FindFirstChild("TextLabel").Text = "Starting game..."
end
end
end)
the reason this doesn’t work is because you need to change the gui in a local script
I would recommend making a remote event and using that to change the gui
casual bump of 7 months, but anyways… The reason why the server script can’t change the text for the client is because each individual client is in charge of their own screen, so then when the server changes a value, it doesn’t necessarily copy over to the client. It’s just way more efficient to directly change the ui on the client’s side.