mercredi 29 juillet 2020

Lua: How do you update a variable that's in an event?

The issue I'm running into is that my variable isn't updating after an event. Here is my code:

local AmountOfPlayers = #Players:GetPlayers() -- starts at zero
local minPlayers = 1


Players.PlayerAdded:Connect(function(Player) -- updates amount of players in server
    AmountOfPlayers = AmountOfPlayers + 1
end)

Players.PlayerRemoving:Connect(function(Player) -- updates amount of players in server
    AmountOfPlayers = AmountOfPlayers - 1
end)

Below, this if-statement is not running since AmountOfPlayers is not equal to minPlayers.

while intermission > 0 do
    if AmountOfPlayers >= minPlayers then
    print("SUCCESS")                
    end
end

I have a scope issue of the variable AmountOfPlayers. I'm not sure how to fix this, so any suggestions will be appreciated. Thank you for your help!

Aucun commentaire:

Enregistrer un commentaire