im doing a Server hop button and the issue rn is everytime i teleport the player it kicks me out cuz the player data haven't loaded yet, and im not sure with what to do before teleporting this is my script
rep.Remotes.ServerHopEvent.OnServerEvent:Connect(function(player, serverid)
local lastServerHopTime = cooldowns[player.UserId] or 0
local currentTime = os.time()
if currentTime - lastServerHopTime < cooldownDuration then
warn("Server hop is on cooldown. Please wait.")
return
end
cooldowns[player.UserId] = currentTime
local profile = PlayerData.Profiles[player]
if profile then
profile:Release()
profile:ListenToHopReady(function()
if serverid then
TeleportService:TeleportToPlaceInstance(game.PlaceId, serverid, player)
else
TeleportService:TeleportAsync(game.PlaceId, {player})
end
end)
else
warn("Failed to release profile for player: " .. player.Name)
end
end)
and this is the function that kicks the player
local function PlayerAdded(player)
local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId)
if profile ~= nil then
profile:AddUserId(player.UserId) -- GDPR compliance
profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
profile:ListenToRelease(function()
PlayerData.Profiles[player] = nil
end)
if player:IsDescendantOf(players) == true then
PlayerData.Profiles[player] = profile
LeaderStats(player, PlayerData.Profiles[player])
rep:WaitForChild("Remotes"):WaitForChild("DataLoaded"):FireClient(player)
else
-- Player left before the profile loaded:
profile:Release()
end
else
-- The profile couldn't be loaded possibly due to other
-- Roblox servers trying to load this profile at the same time:
player:Kick("Couldn't Load Players Data, Please Rejoin The Game")
end
end