I am trying to make a battle game with two teams. One is red team and other is blue team. I want that when both teams have equal players, a bool value will be changed. This is the script I have made up till now. It doesn't work and also doesn't show any error in the output.
What is the problem in the script? I have tried a lot but cannot make it work:
local bluechildren = game.Teams.Blue:GetChildren() local redchildren = game.Teams.Red:GetChildren() local round = game.ReplicatedStorage.RoundInProgress.RoundInProgress game.Teams.Red.PlayerAdded:Connect(function() if redchildren == bluechildren then if round.Value == false then round.Value = true end end end)
Thanks!
The # operator returns the length of something, such as a table or a string. You can use this to get the number of items in conjunction with :GetPlayers(). You also want to put bluechildren and redchildren inside the function, as putting it before will make the value static.
local round = game.ReplicatedStorage.RoundInProgress.RoundInProgress game.Teams.Red.PlayerAdded:Connect(function() local bluechildren = game.Teams.Blue:GetPlayers() local redchildren = game.Teams.Red:GetPlayers() if #redchildren == #bluechildren then if round.Value == false then round.Value = true end end end)
#Team:GetPlayers()
will get the number of Players of a Team.
You should also be using ServiceProvider:GetService()
instead of indexing the DataModel to get all services (except optionally Workspace).