Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

GUI not cloning to every player's PlayerGUI?

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

1 comment

0

Theres no loop so once the server starts or when the script is fired it only runs once :c

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.