Nothing prints and no errors when player leaves

Hello there! Im making settings and save system. I got this script:

game.Players.PlayerRemoving:Connect(function(plr)
local data = game.ReplicatedStorage.RemoteFunctions.PlayerInfo:InvokeClient(plr)
print(data)
dataStore2('Settings',plr):Set(data)
print('End')
end)

But nothing prints. There’s a local script in invoke:

local rs = game.ReplicatedStorage

local plrModule = require(rs:WaitForChild('Modules').PlayerInfo)
rs.RemoteFunctions.PlayerInfo.OnClientInvoke =function()
print('B')
return plrModule.GetPlayerInfo()
end

It doesnt print anything too.

Here try to print something in a random new/blank script. You might be experiencing the same bug I had a while back.

Script doesnt save anything too. But if I put print like this:

game.Players.PlayerRemoving:Connect(function(plr)
print('a')
local data = game.ReplicatedStorage.RemoteFunctions.PlayerInfo:InvokeClient(plr)
print(data)
dataStore2('Settings',plr):Set(data)
print('End')
end)

This will print a

It’s possible that the player instance is deleted when you press the invokeclient thing, resulting in you not getting a result - hence the freezing of the script

Since I use datastore2,i just used :Set() after chaning the settings.

The server invoke does not yield the thread if the return type is nil by default.

I think OP’s script does have a return thing expected though, so it would yield

Correct, however that still would not cause the thread to yield if its return type was nil.

The print that is above the module which is supposed to return something does not get ran, which means the remote fails to invoke. Something fishy is going on.