Documentation code is incorrect (index nil with 'EventId') in case a player didn't join from an event

Code:

local Players = game:GetService("Players")

local function onPlayerAdded(player)
	local source = player:GetJoinData()
	-- Check if the provided source is valid
	if source then
		-- Read eventId from GameJoinContext
		local eventId = source.GameJoinContext.EventId

		if eventId then
			print(player.Name, "joined from the event:", eventId)
		end
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

Output:
image

Page URL: https://create.roblox.com/docs/production/promotion/experience-events

1 Like

Hello @MagicLuau , the reason you are running into this error is because this code sample is specifically running to track the event ID when a player joins an experience through an event entry point, such as by clicking on an event notification or through the join button on the event details page. This process allows the event ID to be added to the player’s GameJoinContext; if they didn’t join from an event, you will run into an error.

Its exactly the issue, it should be probably be good to add a check if there is no such gamejoincontext to prevent users to encounter the following issue.

1 Like

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