Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

GUI not cloning to every player's PlayerGUI?

Asked by 8 years ago

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
0
Theres no loop so once the server starts or when the script is fired it only runs once :c User#5978 25 — 8y

1 answer

Log in to vote
2
Answered by
NotSoNorm 777 Moderation Voter
8 years ago

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
Ad

Answer this question