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

Why isn't this IntValue responding to the functions?

Here is the script I'm using, I'm not sure why it isn't working. Can anybody help?

PlayerCount = game.ReplicatedStorage.Players.Value 

game.Players.PlayerAdded:connect(function()
	PlayerCount = PlayerCount + 1
		
	
end)

game.Players.PlayerRemoving:connect(function()
	PlayerCount = PlayerCount - 1
	
end)

2 answers

✓ Accepted answer

You get the value and not re-assign the value to the Actual Value-Object try something like this:

PlayerCount = game.ReplicatedStorage.Players

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

game.Player.PlayerRemoving:connect(function()
	PlayerCount.Value = PlayerCount.Value - 1
end

but why even use a custom thing if you can just use

game.Players.NumPlayers

1 comment

0

Thanks I used PlayerCount.Value = game.Players.NumPlayers and it worked :D Thank you!

If it's in the Replicated Storage, I suggest you use NumberValues which are easier to use.

If you changed to NumberValue then try with this script; NOTE: Make sure it's a script in ServerScriptService

local PlayerCount = game.ReplicatedStorage:WaitForChild("Players").Value --Make sure Players is a NumberValue
 
game.Players.PlayerAdded:connect(function()
    PlayerCount = PlayerCount + 1
end)
 
game.Players.PlayerRemoving:connect(function()
    PlayerCount = PlayerCount - 1
end)

If helped then please accept answer and upvote. If you have problems comment on errors or other things.

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