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

game.Players.Changed is not working?

Asked by
Daanni 10
9 years ago

This is kind of weird. Basically, I have this script that just updates a value to the current number of players in the game

game.Players.Changed:connect(function (NumPlayers)
    System.CurrentPlayers.Value = game.Players.NumPlayers
end)

Now, whenever I do local testing (F5 on keyboard) it updates the value fine. BUT whenever I do local server emulation or whatever it is called (F7 on keyboard) the Value does NOT update properly. Now, if I change my code to this:

game.Players.PlayerAdded:connect(function (NumPlayers)
    System.CurrentPlayers.Value = game.Players.NumPlayers
end)

It updates even during server emulation. HOWEVER, the second variation only updates the player count when someone joins the game, and not when someone leaves. Does anyone have any idea why .Changed is not working? And, even if it does work in a regular game with regular players, it not working in server emulation is a serious problem for me (for when I am debugging alone).

1 answer

Log in to vote
1
Answered by 9 years ago

The reason why Changed doesn't work? I don't know, how to make the Value of players decrease when players leave? Easy:

game.Players.PlayerAdded:connect(function ()
    System.CurrentPlayers.Value = System.CurrentPlayers.Value+1
end)

game.Players.PlayerRemoved:connect(function ()
    System.CurrentPlayers.Value = System.CurrentPlayers.Value-1
end)

Also, when you were doing your script:

game.Players.PlayerAdded:connect(function (NumPlayers) --Notice the function (NumPlayers)
    System.CurrentPlayers.Value = game.Players.NumPlayers
end)

If you were to do System.CurrentPlayers.Value = NumPlayers the script would error because NumPlayers Would be an object value.

0
It says that "PlayerRemoved" is not a valid member of "Players" Daanni 10 — 9y
0
Do game.Players.PlayerRemoving Vlatkovski 320 — 9y
Ad

Answer this question