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

PlayerRemoving not being called when player leaves, why?[SOLVED]

Asked by 7 years ago
Edited 7 years ago

I have a script in the "ServerScriptService" folder and in the script i have:

function playerLeft(player)
    print("numPlayers: ",#Players["players"])
    for i = 0,#Players["players"] do 
        print("Player: "..Players["players"][i]," is the same as: "..player.Name,": ",Players["players"][i] == player.Name)
        if Players["players"][i] == player.Name then 
            table.remove(Players["players"],i)
        end 
    end 
    local encodeData = http:JSONEncode(Players)
    local anythingReturned = http:PostAsync(url,encodeData)
    local decodedDataReturned = http:JSONDecode(anythingReturned)
end
game.Players.PlayerRemoving:connect(playerLeft)

But it doesn't get called, why? I have no idea how to fix this, no error comes up. I've also looked at Roblox Wiki and it seems like i'm using it properly.

1 answer

Log in to vote
0
Answered by 7 years ago

I was having a brainfart moment. I realised i had an infinite loop above the function which would have never added the event listener which in return would not have called the playerLeft function when a player leaves the game.

1
nice DepressionSensei 315 — 7y
Ad

Answer this question