Attempt to index nil with (Teleport data)

I have a script that makes it so that when you are teleported to that place in the game, it will check if your in a certain colony. Each time i test it, it says “Attempt to index nil with SubLimitless” (SubLimitless is my userame)

In the script that gives the data, it prints lua teleportdata[v.Name].VColonyValue the correct way without any errors, unlike the 2nd script (the one below that fires when you join the other place which i was talking about before)

Code for 2nd script (error):

game.Players.PlayerAdded:Connect(function(player)
	task.wait(3)
	local joindata = player:GetJoinData()
	local teleportdata = joindata.teleportdata
	
	local colonyvalue = teleportdata[player.Name].VColonyValue
end)
1 Like

if you get that error, that means teleportdata is nil which means that player:GetJoinData() probably is nil as well, maybe check that.

how would i check that, if i print it does this
Screenshot 2025-03-02 003108

enable the output in the “view” tab on roblox studio and make sure that log mode is disabled

it is, it was off beforehand too

What do you get inside the output console?

if i test from studio: (the yeh thing was from another test, not this)

if i test ingame (i printed joindata first then colonyvalue)
Screenshot 2025-03-02 003655

I assume {} in the output window on studio is the joindata ?

What exactly are you trying to do with :GetJoinData() ?

{} is the joindata
I use :getjoindata() to get the join data of the player when they teleported from another place, I learnt it from a tutorial

Alright, but this is not working as joindata in your case is just an empty table.

Couldn’t you use data from the datastores, cause you won’t get any data if you’re not putting any data?

I entered the game in studio when it showed the {}, meaning i wasnt in the starter place before that, meaning there was no teleport data because i didnt teleport

I am inputting data though, this is the teleporter script that teleports me to the 2nd place where i got the original error from

lines 26, 27, 28, 44, 45 and 46 show me putting data

local teleportservice = game:GetService("TeleportService")
local replicatedstorage = game.ReplicatedStorage
local escapeguione = replicatedstorage:WaitForChild("EscapeGuiOne")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local humanoid = hit.Parent.Humanoid
		local colony = hit.Parent.Colony
		local arrayofplayers = {
			
		}
		for i, v in pairs(game.Players:GetPlayers()) do
			if v.Character:WaitForChild("Colony").Value == colony.Value and colony.Value ~= "" then
				if game.ReplicatedStorage.ColonyStuff:FindFirstChild(colony.Value).MemberPermsFolder.MembersCanExit.Value == true or game.ReplicatedStorage.ColonyStuff:FindFirstChild(colony.Value).ColonyLeaderValue.Value == humanoid.Parent.Name then
				table.insert(arrayofplayers, v)
				
				teleportdata = {
	             
				}
				
					teleportdata[v.Name] = {v.Name}
					for i, v in pairs(teleportdata) do
						print(v)
					end
					
					table.insert(teleportdata[v.Name], "VColonyValue")
					teleportdata[v.Name].VColonyValue = v.Character.Colony.Value
					print(teleportdata[v.Name].VColonyValue)
					
					for i, v in pairs(teleportdata) do
						print(v)
						--for e, t in pairs(teleportdata[v.Name]) do
							--print(t)
						--end
					end
				
				end
			elseif v.Character.Name == hit.Parent.Name then
				teleportservice:Teleport(98985454249054, game.Players:GetPlayerFromCharacter(hit.Parent))
				print("teleported one player not in a colony")
			end
		end
		
		local teleportoptions = Instance.new("TeleportOptions")
		teleportoptions:SetTeleportData(teleportdata)
		teleportservice:TeleportAsync(98985454249054, arrayofplayers, teleportoptions)
		
	end
end)

erm just an observation I don’t see any line 7 from either script that could return the error you showed in the picture. It would help to see where that line 7 error is coming from since that’s the whole reason for this post

local colonyvalue = teleportdata[player.Name].VColonyValue

1 Like

From what I see, this simply means teleportdata is nil, which implies joindata or joindata.teleportdata is nil as well

also by the way, I updated the script and put TeleportData instead of teleportdata (used tutorial) and it seemed to remove the error but the value is still nil

Since you cannot directly test on studio, could you please add this to your script?

for i, v in pairs(TeleportData) do
print(i,v)
end

… and reply with a screenshot of the output ingame?

Wait, when you said you changed the name to TeleportData, were you speaking about the variable name or :GetJoinData().TeleportData ? Whatsoever, make sure you wrote :GetJoinData().TeleportData, not teleportdata

I was talking about the GetJoinData().TeleportData

Then change the variable name as well and run again :skull: