Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to check if the player is online and in my game for cross server purposes?

Asked by 8 years ago

Is it possible to check if a player is online, and in your game?

I've got a system, but it's not working the way I wanted it too.

local function savePlayerData(player)
    if sessionData[player] then
        return dataStoreRetry(function()
            return FriendData:SetAsync(player.userId, sessionData[player])
        end)
    end
end

local function setupPlayerData(player)
    local success, data = getPlayerData(player)
    if not success then
        sessionData[player] = false
    else
        if not data then
            sessionData[player] = {}
            savePlayerData(player)
        else
            sessionData[player] = data
        end
    end
end

function DataStore:UpdateStatus(player, isOnline)
    for i = 1, #sessionData[player] do
        local friendID = game.Players:GetUserIdFromNameAsync(sessionData[player][i]["Name"])
        if friendID ~= nil then
            output(player, ":", friendID)
        end

        local playerData = FriendData:GetAsync(friendID)

        if playerData ~= nil then
            for i2 = 1, #playerData do
                for i3 = 1, #playerData[i2] do
                    if playerData[i2][i3]["Name"] == player.Name then
                        playerData[i2][i3]["Online"] = isOnline
                    end
                end
            end

            FriendData:SetAsync(game.Players:GetUserIdFromNameAsync(sessionData[player][i]["Name"], playerData))
        end
    end
end

game.Players.PlayerAdded:connect(function(plr)
    setupPlayerData(plr)
    DataStore:UpdateStatus(plr, true)
end)

game.Players.PlayerRemoving:connect(function(plr)
    DataStore:UpdateStatus(plr, false)
    savePlayerData(plr)
end)
0
"Is it possible to check if a player is online, and in your game?" Yes. If they're in your game, they must be online. Therefore: if game.Players:FindFirstChild("bob") then Perci1 4988 — 8y
1
Yeah, not sure what you're asking exactly. There's no way of checking if they're online if they're not in you game I don't believe. = User#11440 120 — 8y
0
I think he's wanting to see if he can get a player from another server, which I assume is possible. PreciseLogic 271 — 8y
0
@PreciseLogic: This is what I was after.. I want to be able to get if they're in my game, but on a different server. Hints the whole friend things. TinyPanda273 110 — 8y
0
Not sure if this would help, https://github.com/matthewdean/roblox-web-apis LittleBigDeveloper 245 — 8y

Answer this question