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

Why isn't this IntValue responding to the functions?

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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
0
Thanks I used PlayerCount.Value = game.Players.NumPlayers and it worked :D Thank you! Shadi432 69 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

Answer this question