I've been trying to make this GUI which makes it appear if there aren't enough players in the server. When I go to start a server with 2 players (the minimum amount the script needs), it shows up for one player, but doesn't for the other. This is inside of a GUI, and it's a LocalScript.
local reqPlayers = 2 local reqPlayersText = game.StarterGui.ReqPlayersGUI:FindFirstChild("ReqPlayersText") -------------------------------- if game.Players.NumPlayers < reqPlayers then script.Parent.Visible = true script.Parent.Text = "Two or more players are needed to begin." repeat wait() until #game.Players:GetPlayers() >= 2 wait(2) reqPlayersText.Text = "The game is now ready!" wait(2) reqPlayersText:TweenPosition(UDim2.new(0,-150,0,250), "Out", "Bounce", 0.35, true) end
what you're trying to do is change the startergui, change the player gui.
this will check every 10 seconds for the players in game
local reqPlayers = 2 local reqPlayersText = game.Players.LocalPlayer.PlayerGui.ReqPlayersGUI:FindFirstChild("ReqPlayersText") -------------------------------- while wait(10) do --let's do 10 so it doesn't lag if #game.Players.NumPlayers < reqPlayers then script.Parent.Visible = true script.Parent.Text = "Two or more players are needed to begin." repeat wait() until #game.Players:GetPlayers() >= 2 wait(2) reqPlayersText.Text = "The game is now ready!" wait(2) reqPlayersText:TweenPosition(UDim2.new(0,-150,0,250), "Out", "Bounce", 0.35, true) end end
[edit] Now what we could do to make it only fire when a player has joined or left is....
function checkplayers() if #game.Players.NumPlayers < reqPlayers then script.Parent.Visible = true script.Parent.Text = "Two or more players are needed to begin." repeat wait() until #game.Players:GetPlayers() >= 2 wait(2) reqPlayersText.Text = "The game is now ready!" wait(2) reqPlayersText:TweenPosition(UDim2.new(0,-150,0,250), "Out", "Bounce", 0.35, true) end end game.Players.PlayerAdded:connect(function() checkplayers() game.Players.PlayerRemoving:connect(function() checkplayers() end end