You can write your topic however you want, but you need to answer these questions: 1. What do you want to achieve? Keep it simple and clear!
I want to change the MaxPlayer for my game to 20
2. What is the issue? Include screenshots / videos if possible!
I have followed the roblox documentation on MaxPlayers and have changed the game setting so the place now have 20 max players. However, the player’s property for MaxPlayer still set to 60. And also print(game:GetService(“Players”).MaxPlayers in console confirms it’s still 60 players.
Use #help-and-feedback:platform-usage-support For stuff like this, As for the answer to your problem. Be sure youre editing that second place page, or click the three dots next to the place, you wanna edit > Configure Place > Max Players
wait like… like the screenshot I gave above right? it’s already saying 20 MaxPlayers but property for MaxPlayer still set to 60. And also print(game:GetService(“Players”).MaxPlayers in console confirms it’s still 60 players.
I will change the topic category for this tho… But ur one is completely fine? can I please also see your player property on the explorer page. Just need to confirm if it’s just my one or what.
This is unfortunately a bug that is still happening. In studio, this property does not change at all even when playing the game. In a live server, however, it seems as though the property changes after ~a second to it’s proper value.
This is the code I used to test the behavior and the results:
--!strict
local Players = game:GetService("Players")
local function outputMaxPlayers(notChanged: boolean?): ()
if notChanged == true then
print(`MaxPlayers set to`, Players.MaxPlayers)
else
warn(`MaxPlayers updated to`, Players.MaxPlayers)
end
end
game.Players:GetPropertyChangedSignal("MaxPlayers"):Connect(outputMaxPlayers)
outputMaxPlayers(true)
A hacky solution you can use for now in live servers is to do something like this until this bug is fixed if you need to rely on this property:
--!strict
local Players = game:GetService("Players")
-- function to wait for the MaxPlayers property to change. Otherwise,
-- return the current Players.MaxPlayers property after 'timeout' seconds.
local function waitForRealMaxPlayers(timeout: number): ()
local mainThread: thread = coroutine.running()
local delayedThread: thread = task.delay(timeout, task.spawn, mainThread, Players.MaxPlayers)
local changedConnection: RBXScriptConnection = Players:GetPropertyChangedSignal("MaxPlayers"):Once(function(): ()
task.spawn(mainThread, Players.MaxPlayers)
end)
local maxPlayers: number = coroutine.yield()
pcall(task.cancel, delayedThread)
changedConnection:Disconnect()
return maxPlayers
end
-- wait up to a maximum of 5 seconds if the
-- MaxPlayers property has not yet changed
print("MaxPlayers:", waitForRealMaxPlayers(5))
Aw thank you so much for the pointers. And most importantly confirming that it’s not just me going crazy lol. I gotta be honest, I’m kind of lost with all the coroutine stuff on your code. I’ve always wanted to learn them but so far if I need to do a multi thread stuff, I just use a task.spawn() so far. Like I meant specifically when I need to do something which gets blocked by a while loop kind of thing.
And I didn’t even know there’s a :Once() method. So yeah, thank you so much again! I learned a lot from the code you posted for other stuff, not just the MaxPlayer thing.