Here's my script:
playerCount = {} Players = Game:GetService("Players") Players.PlayerAdded:connect(function(Player) table.insert(playerCount, Player.Name) print(table.concat(playerCount, ", ")) end) Players.PlayerRemoving:connect(function(Player) for index = 1, #playerCount do if playerCount[index] == Player.Name then table.remove(playerCount, index) print(table.concat(playerCount, ", ")) break end end end) epic = true while epic == true do if #playerCount == 2 then local hint = Instance.new("Hint", Workspace) hint.Text = "The game will begin shortly." epic = false else hint = "Two people are needed to start the game." end end
The only thing I have a problem with is that last part.
What it's supposed to do is: until 2 players have entered, it's gonna have a hint at the top of the screen saying "Two players are needed to start the game." until 2 players have entered. Once 2 players have entered, it will show a hint saying, "The game will begin shortly."
Only, no hint is showing up whenever I do it.
Please help me with this.
Yeah. Some general tips on this:
#game.Players:GetPlayers()
for this.In the case that there are not two players - a non-waited while loop runs. This should crash your script. In the case there are more or two players - epic is set to false and the loop will break, never checking this again. You want to set the hint text, not the hint itself (line 25). (So, this won't actually create or set a hint)
Let me provide a fix:
function GetNumplayers() return #game.Players:GetPlayers() end local Hint = Instance.new("Hint", game.Workspace) while wait(1) do if GetNumplayers() >= 2 then Hint.Text = "The game will begin shortly" else Hint.Text = "Two people are needed to play this game" end end
Locked by TheMyrco
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?