When the player is teleported to a place of mine, their data doesn’t load like it usually does when normally joining the place, causing all of my scripts relying on that data to break. (I’m using ProfileService, and am not too familiar with how it works so that might be part of the problem)
local function PlayerAdded(player: Player)
print("Player added, loading their data") -- This prints immediately
local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId.."_Save5")
if not profile then player:Kick(KICK_MESSAGE) return end
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Manager.Profiles[player] = nil
player:Kick(KICK_MESSAGE)
end)
if player:IsDescendantOf(Players) == true then
print("Data loading now") -- Prints ~8 seconds later
Manager.Profiles[player] = profile
CreateDataFolder(player)
dataEvent:FireClient(player, "loadCards", profile.Data.Cards)
dataEvent:FireClient(player, "loadEquippedCards", profile.Data.EquippedCards)
else
profile:Release()
end
end
The prints that I’ve used for testing fire at vastly different times, with the one that actually loads the data firing a whole 8 seconds later. This means that the player isn’t a descendant of “Players” until ~8 seconds after they’re teleported. How can I fix my issue?