PlayerAdded not firing in Play Solo?

I definitely know this is an issue with the way my script is set up and not a bug, because PlayerAdded fires in every other circumstance. I require help.

I’ve cut off a lot of the script and it refuses to fire. A snippet is posted below (hey, free code for reference, problem aside!).

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local TeleportService = game:GetService("TeleportService")

local SessionData = {}
local CoreDataStoreName = "COREDSNAME"
local MenuDataStoreName = "MENUDSNAME"

local PlayerDataStore = DataStoreService:GetDataStore(CoreDataStoreName)
local BackupPlayerDataStore = DataStoreService:GetDataStore(CoreDataStoreName, "Backup")

local Defaults = PlayerDataStore:GetAsync("Default") -- Returns defaults table; reduces DS calls

-----

local function WaitForRequestBudget(RequestTypeEnum, RequestsRequired)
	local RequestBudget = 0
	local MinimumRequests = ((RequestsRequired and type(RequestsRequired) == "number") and RequestsRequired or 0)
	repeat
		RequestBudget = DataStoreService:GetRequestBudgetForRequestType(RequestTypeEnum)
		wait(0.5)
	until RequestBudget > (MinimumRequests + 2)
end

-----

Players.PlayerAdded:Connect(function (Player)
	print("hi")
	SessionData[Player.UserId]				=	{}
	SessionData[Player.UserId]["Main"]		=	{}
	SessionData[Player.UserId]["Menu"]		=	{}
end)

^ “hi” won’t print.

I’m not sure if it works in a live server, but I need to work in Play Solo so I can develop with the place listed as private. The script is not disabled, Studio has API access, HttpService is enabled and Experimental Mode is off.

2 Likes

One issue I often come across while testing in PlaySolo is that the player joins before the script has time to setup the listener for the PlayerAdded event.

Just by looking at your code, it appears the :GetAsync() method call is the issue here, because it stops the script execution for however long it takes to get stuff from the DataStore.

You have four possible solutions:

  1. Mix up the order of how stuff happens so you setup the listener first
  2. Do the GetAsync synchronously (using a coroutines or something – though it may break your PlayerAdded listener when it tries to reference Defaults which may be nil at the time)
  3. Loop through Players:GetPlayers() when the script runs – might need to make a table storing players who have been setup already to act as a debounce
  4. Test using a local server/proper server
5 Likes

GetAsync works fine and doesn’t stop the script execution. I added a print underneath it and it printed a table as expected. Adding a print before and after the WaitForRequestBudget function also is fine. It’s only the PlayerAdded that refuses to run.

Will try the provided solutions and see what works, though.

1 Like

I meant it stops the script execution temporarily - long enough for the player to be added before the listener is connected.

2 Likes

Oh yeah. It’s definitely got to be that. I put this at the top of the script before any other lines and the event fired (not the one that’s the problem child; the snippet below).

game.Players.PlayerAdded:Connect(function () print("yaaaaaa") end)

Thanks. I’ll move the GetAsync.

1 Like

Just dug up this thread I made last year :wink:

Play Solo has a long term to be fixed which is cool

1 Like

Yeeee, thanks. It seems that I still have a bit to delve into regarding scripting. I don’t have the right definition of script execution (I thought of it as something else) so that’s why I’ve been having a few problems where there shouldn’t be problems. Moving the GetAsync into the PlayerAdded event solved the problem. It’s fine to leave it there though, since it’s a 1-player server; if it has more players, I can use a different method.

ok that being said I need to go and edit years worth of work to fix my errors

Enjoy the free WaitForRequestBudget function.

1 Like