Exception while signaling, unable to cast to dictionary Error

local TeleportService = game:GetService("TeleportService")
local gameID = 11973335326
local teleportData = "Brother Stop Error"
 
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
		TeleportService:TeleportToSpawnByName(gameID, "AP", player, teleportData)
    end
end
 
script.Parent.Touched:connect(onTouched)

I keep getting that error. Is it me or is it something with my script as I do not see anything wrong with me script

Is it actually a string or is that just an example you changed it to for clarity? Because it will throw if teleportData is a mixed table so that might be it

If I’m not mistaken, your variable teleportData requires a table datatype to be passed through within your fourth argument through the TeleportToSpawnByName() function judging by the error

Since it’s trying to look for a Dictionary, try replacing teleportData with this instead:

local teleportData = {
    Data1 = "Brother Stop Error"
}

And when you want to receive the said Data on a different place, you can use the GetLocalPlayerTeleportData() function and it should Output back with the data you originally sent on that first place

-- On a different place through a LocalScript
local TeleportService = game:GetService("TeleportService")
local Plr = game.Players.LocalPlayer

local PassedData = TeleportService:GetLocalPlayerTeleportData()
print(PassedData) 

its actually a string, sorry for the late reply i was asleep

1 Like

Here is the code
local TeleportService = game:GetService(“TeleportService”)
local gameID = 11973335326
local teleportData = “Brother Stop Error”

function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:TeleportToSpawnByName(gameID, “AP”, player, teleportData)
end
end

script.Parent.Touched:connect(onTouched)