I’ve noticed over the past while that sometimes when testing using Play Solo, if a script using PlayerAdded takes longer than ~0.0003 seconds, the PlayerAdded event will have fired before the script creates the listener.
Often in this situation I will either have to change how my code works or do every single little test in a local server simulation. Both of these decrease my efficiency when developing and make the debugging process more annoying than it has to be.
A possible solution could be to have an option to adjust the time delay between running the test and creating the player - my problem would be solved if the player waited 0.1 more seconds before joining.
It’s a good pattern to always loop over Players:GetPlayers() and call your onPlayerAdded function before you hook up to the PlayerAdded event. That way, it will always work in play solo and the script can also be started mid-game and not have issues.
Example:
local Players = game:GetService("Players")
local function onPlayerAdded(player)
print("Player " .. tostring(player) .. " joined")
end
for _,player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
There is a long term plan to fix play-solo. Right now play-solo is broken for FE purposes. It is also commonly used to report problems, but without people specifying it.
That problem is harder though – it is nice to have a single explorer, but in reality there is one for client and one for server.
The only solution for that would be to have extra stuff checking to see, if in an FE situation, things that happen would happen, and change their effects accordingly, right?
Either way, good luck, and I hope you somehow fix my problem during the update
A realistic plan might involve Studio moving to 64b and then just having multiple data models. It would also be possible to spin up child server/client processes that are just not displayed at all times. There are multiple options on the tech. However the presentation is important.
Play-Solo isn’t FE or non-FE. It is a weird model that mostly matches non-FE and is used only for convenience.
Not sure how soon, but it is something that we are looking into. Play-Solo doesn’t match either networked model and can be confusing to new users – especially /wrt FE games.