Custom Events don't work Analytic

players.PlayerRemoving:Connect(function(player)
	
	local key = player.UserId
	local statsFolder = player:WaitForChild("leaderstats")
	local rebirths = statsFolder:WaitForChild("Rebirths").Value
	local deaths = statsFolder:WaitForChild("Deaths").Value
	local stage = statsFolder:WaitForChild("Stage").Value
	
	local data = {
		
		["Rebirths"] = rebirths

	}
	
	local succes, response = pcall(function()

		playerDatastore:SetAsync(key, data)

	end)

	if not succes then

		warn(response)
	
	end
	
	local AnalyticsService = game:GetService("AnalyticsService")


	AnalyticsService:LogCustomEvent(
		player,
		"Stage on quit",
		stage
		
	)
	
	AnalyticsService:LogCustomEvent(
		player,
		"Deaths on quit",
		deaths

	)
	
end)


1 Like

Custom events don’t work in Studio similar to teleportService.

the game is pubblished and people joined but still nothing

It’s probably because the player instance is nil if I’m being honest.

ohhh your right!

what can i do to fix that? i want to log the event on player removing

Maybe put the logging and data saving into two separate threads. This will allow you to save and log right before the player fully leaves

ok thanks charactersssjijijijjjjj

I realized you don’t need two you need 1. I’m not sure if logging yields but you should do it should be like this:

players.PlayerRemoving:Connect(function(player)
	local AnalyticsService = game:GetService("AnalyticsService")

	AnalyticsService:LogCustomEvent(
		player,
		"Stage on quit",
		stage

	)

	AnalyticsService:LogCustomEvent(
		player,
		"Deaths on quit",
		deaths

	)


	task.spawn(function()
		local key = player.UserId
		local statsFolder = player:WaitForChild("leaderstats")
		local rebirths = statsFolder:WaitForChild("Rebirths").Value
		local deaths = statsFolder:WaitForChild("Deaths").Value
		local stage = statsFolder:WaitForChild("Stage").Value

		local data = {

			["Rebirths"] = rebirths

		}

		local succes, response = pcall(function()

			playerDatastore:SetAsync(key, data)

		end)

		if not succes then

			warn(response)

		end
	end)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.