I tried making a script that can change a value when all players are below the rank level
My issue is it wont run and im not sure why.
My thought process
Line 1: Reference players
Line 2: Get the children of players (Aka get all players)
Line 3: Check if there classname = Player
Line 4: Add a player removing so my script can be triggered to check what I need it to
Line 5: Check if all players are below the rank level
Line 6: Change value
Any tips? help is appreciated
local ps = game.Players
for _, v in next, ps:GetChildren() do
if v:IsA("Player") then
game.Players.PlayerRemoving:Connect(function(Plr)
if v:GetRankInGroup(GroupID) <=199 then
game.Workspace.Hosting.Value = false
end
end)
end
end
You should actually reverse the statement with > instead of <=. Then you have to check every player that are still over that rank every time, either by separating a table with only them… or iterate all players(worse than the former option).
Be careful of the connection still remaining a reference after it is there. It may cause some nasty leaks to the game if you don’t manage them well.
Hey you have some mistakes in your script.
first of all, No need to check if children of game.Players are player, because they are, nothing else is in there.
second of all, you are adding player removing function a number of times(number of players), meaning if there are two players then it will fire two time when one player leaves.
And lastly, when a player leaves you should recheck if there are any players left which are A rank, but in your script if one ranked player leaves, it disables hosting, whether or not there are other group ranked players in the server.