Cannot use :FindFirstChild on a dictionary

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    This script to send to the function whenever someone joins what place they joined from, and if not, ROBLOX.
  2. What is the issue? Include screenshots / videos if possible!
    :FindFirstChild() isnt working at all and everything else i have tried hasnt worked.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried putting in different functions that look for it, i have tried doing [“SourcePlaceID”], and i have tried lots more.
game.Players.PlayerAdded:Connect(function(player)
	local joindata = player:GetJoinData().TeleportData
	local productinfo = nil
	
	if game.MarketplaceService:GetProductInfo(joindata:FindFirstChild("SourcePlaceID")) then	-- this parts the annoying part
		productinfo = game.MarketplaceService:GetProductInfo(joindata:FindFirstChild("SourcePlaceId").Name)
	else
		productinfo = "Roblox"
	end
	datasend(player, " has joined the Main Menu, from "..productinfo, colors.join)
end)
2 Likes

Dictionaries cannot be used like that only instances!
You should use a for loop if you want to find something but in your case just doing,
joindata.SourcePlaceID

No FindFirstChild required!
tables; table | Documentation - Roblox Creator Hub
Arrays and dictionaries | Documentation - Roblox Creator Hub
that may help idk

Hey @JeffDaAwesomeDu!

The issue is that TeleportData is a Lua table, not an Instance. So :FindFirstChild("SourcePlaceId") will never work.

Instead, access it like this:

local teleportData = player:GetJoinData().TeleportData

if teleportData and teleportData.SourcePlaceId then
	local productInfo = game.MarketplaceService:GetProductInfo(teleportData.SourcePlaceId)
	datasend(player, " has joined the Main Menu, from "..productInfo.Name, colors.join)
else
	datasend(player, " has joined the Main Menu, from Roblox", colors.join)
end

That should fix your issue. (:

2 Likes

It works, but now it always says the player joined from roblox…

1 Like

That means the player is not coming from a teleport, in this case, TeleportData will be nil or won’t contain SourcePlaceID

To check this properly, try debugging with:

print("JoinData:", joindata)
print("SourcePlaceID:", joindata and joindata.SourcePlaceID)

Also, make sure that when you teleport the player from another place, you’re using:

TeleportService:Teleport(placeId, player, {
    SourcePlaceID = game.PlaceId
})

Otherwise, TeleportData won’t include that info and will default to “Roblox” :grimacing:

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