As a Roblox developer, it is currently too hard to LogCustomEvent in the Players.PlayerRemoving event. We are trying to see after player joined a battle, when do they leave. So intuitively, we use:
Players.PlayerRemoving:Connect(function(player: Player)
print(player.Parent) -- this print out "nil"
local inBattleTime = tick() - _G.battleStartTime
AnalyticsService:LogCustomEvent(player, "LeaveBattleTime", inBattleTime)
end)
When the event does triggered, analytics service gives an error:
AnalyticsService: player must be a child of 'Players'.
Some developers suspected that we are running the code in another thread so the player.Parent becomes nil. Further investigation reveals that our workspace settings “SignalBehaviour” is set to “Deferred” which is the current Roblox prefered setting. Changing the behaviour to “Immediate” seems to solve the problem and the player.Parent remains Players. However, we are not comfortable with changing the setting away from what Roblox prefers.
If Roblox is able to address this issue, it would improve my development experience because we will not need to risk having problems in other part of existing codes that may be affected by the signal behaviour settings. And we do not want to constantly fire a lot of such custom events just to get the last battle time event.