I am trying to add a script to my game, that if my total player count exceeds 10 it would display a message. But I am not sure how to do this since the MaxPlayers is 5.
I’ve been looking all over the place for this and everything says to use HTTPService and proxies and all that but that would leave my game vulnerable.
I am trying to find the total numbers of players in my game. And HttpService is vulnerable because on the hacking site “v3rmillion” there is an exploit to take advantage of HttpService
You want to send me that? Because I’ve been doing web development since I was 9, and almost all of my recent projects have used HttpService and we have had no problems what so ever.
I don’t know much about how exploits work and all that so I don’t know if it’s actually on there or not, I have seen many exploiters use it and one has showed me it but I didn’t copy it.
Well I will still go with those posts because 2 people are now saying there is no vulnerability in HttpService. They were probably using a backdoor virus in the game or something along the lines of that.
I had a new developer ask me how I would go about doing this, and after spending an hour investigating the complexities of HttpService. I sorted out a simple solution via a DataStore, that does not suffer from server overwrite issues thanks to UpdateAsync().
This should work as requested.
local universeData = game:GetService("DataStoreService"):GetDataStore("universeMetadata") -- Reference or create datastore for our use (any name can be used)
--
local newCount, oldCount, countDiff; -- Creating local references
--
local function increment(oldValue) -- Safe icrementing function
return math.clamp((oldValue or 0)+countDiff, 0, math.huge)
end;
--
local function updatePlayerCount(overrideCount)
newCount = overrideCount or #game.Players:GetChildren(); oldCount = oldCount or 0;
--
if newCount ~= oldCount then
countDiff = newCount-oldCount
--
oldCount = newCount;
--
local success, err = pcall(function()
universeData:UpdateAsync('currentPlayers', increment)
end)
end
--
_G.currentPlayers = universeData:GetAsync('currentPlayers') or 0; -- We save the return for our own use in game, such as for a UI to reference. Global makes it easier;
--
print(_G.currentPlayers)
end;
--
game:BindToClose(function() -- We bind an override function to ensure the server will subtract all remaining players from the count on shutdown
updatePlayerCount(0)
end)
--
while wait(10) do -- We use a single while loop at a reasonable frequency to prevent sending to many update requests.
updatePlayerCount();
end;