Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Int Value adding not working when a player is being added. HELP?

game.Players.PlayerAdded:Connect(function()
	game.Workspace.Value.Value = game.Workspace.Value.Value + 1
end)

This script is supposed to add 1 to in value if a person join but it doesnt work. Any help will be appreciated!

1 comment

0

Are there any errors in console?

1 answer

Well first of all, if you are trying to get the amount of players in a game, just do

game.Players:GetChildren()

This will return an array of every player in the game when that is called, so if you want how many people, just add # in front like this

#game.Players:GetChildren() — This will return a number

As for your code, there isn’t much i can do, since it appears to be correct to me, so just check to make sure that that script is in ServerScriptService, and check for spelling, and make sure it actually exists, also you did not tell us what was not working about it, were there any errors?

But I would not reccomend using that to count players, use the method I showed you. Your method is bad practice and may not function as intended.

Also the PlayerAdded event has a parameter, which is the player that joined. Here is an example:

game.Players.PlayerAdded:Connect(function(Player)
     print(Player.Name)
end)

That will print the players name whenever they join.

I hope this helps.

2 comments

0

I would recommend :GetPlayers() function instead.

0

Yeah that’s what I meant lol

This discussion is preserved as it was. New answers, comments, and votes are closed.