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

Why does this value not change with this script? How should I fix it? Please explain why.

Script:

amountofPlayers = workspace.Server.Players.Value

game.Players.PlayerAdded:Connect(function(player)
	
	amountofPlayers = amountofPlayers + 1
end)

2 comments

0

Pointers don't exist in Lua, you've simply just allocated the Value's state into amountofPlayers. If you want to change the property, you'll have to index it each time.

0

Sorry, I'm pretty dumb in terms of code. Could you simplify it?

1 answer

✓ Accepted answer

Pointers don't exist in Lua, you've simply just allocated the Value's state into amountofPlayers. If you want to change the property, you'll have to index it each time

--// This is what's actually happening.
amountofPlayers = workspace.Server.Players.Value
(amountofPlayers = 5) --// [Per say]

You need to:

local Players = game:GetService("Players")


local AmountOfPlayers = workspace.Server.Players


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

You should also know, that you can determine the number of Players in-game this way:

local Players = game:GetService("Players")


print(#Players:GetPlayers()) --> 5

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