local function PlayerAdded(player: Player)
player:SetAttribute("Ready", false)
local profile = PlayerProfileStore:LoadProfileAsync("Player_".. player.UserId, "ForceLoad")
if not profile then issue(player, "Unable to load the profile.", true) return end
profile:Reconcile()
profile:ListenToRelease(function()
CachedProfiles[player] = nil
issue(player, "Has been disconnected from the server because profile was released.", true)
end)
if player:IsDescendantOf(Players) then
CachedProfiles[player] = profile
PlayerDataLoaded(player)
else
profile:Release()
end
end
However I need to read and write into profile of a player that is not in the game. However I see that I need player object to do the following…
profile:ListenToRelease(function()
CachedProfiles[player] = nil
issue(player, "Has been disconnected from the server because profile was released.", true)
end)
if player:IsDescendantOf(Players) then
CachedProfiles[player] = profile
PlayerDataLoaded(player)
else
profile:Release()
end
How can I get profile to read and write into it with just UserId?
Why do I need this?
I need this so I can change stuff for the player with commands even if they are not in the game.
I think you need to research the Global Updates mechanism. This would allow you to push updates into a player profile even if they’re currently online.
However, when you push a global update to an offline player, the changes will not be reflected until they are online, as your game will need to process the changes when the player joins.
This is mainly good for gifting, but would also work in your scenario, as it wouldn’t release the session lock for players who are in game—Meaning the player won’t be kicked if they’re in game in another server.
Oh, I just forgot that CachedProfiles is my variable . So I just do this?
local function Do(userId: number)
local profile = PlayerProfileStore:LoadProfileAsync("Player_".. userId, "ForceLoad")
if not profile then return end
profile:Reconcile()
profile:ListenToRelease(function()
profile = nil
end)
profile.Data = ProfileFulfillment:Verify(userId, profile.Data)
profile.Data.Ban.Active = true
profile:Release()
end
That’s just temporary name, since I am still thinking what I want to do.
local function BanPlayer(userId: number)
local profile = PlayerProfileStore:LoadProfileAsync("Player_".. userId, "ForceLoad")
if not profile then return end
profile:Reconcile()
if profile.Data.Ban ~= nil then
if profile.Data.Ban.Active ~= nil then
profile.Data.Ban.Active = true
end
end
profile:Release()
end
looks fine to me, but again you can remove the reconcile. this is used to “fill in” missing data; for example, if you added a new stat to your game. you don’t need to waste any resources with reconciliation if you’re just banning the player
What if ban property doesn’t exist on the player? My game had serious datastore issues because of my lack of knowledge in the past and there was no such thing as Ban key in the player data.
local function BanPlayer(userId: number)
local profile = PlayerProfileStore:LoadProfileAsync("Player_".. userId, "ForceLoad")
if not profile then return end
if not profile.Data.Ban then
profile.Data.Ban = {}
end
if not profile.Data.Ban.Active then
profile.Data.Ban.Active = true
end
profile:Release()
end
you can just create the ban table if it doesn’t exist
While your here, I’m working gonna start working on a logging system here in the next few days [In-Game cad system for getting players arrest history etc while they are offline]
I don’t need to override any of the players data I just need ReadOnly values would the
ProfileStore:ViewProfileAsync(profile_key, version) - Work for this?
And to add onto it how would I get the version? If it left it blank does it get the latest?
I’ve just started using ProfileService a little over a week ago so I’m not too familiar with the API.
I was talking about ProfileService, I don’t really know much on whats going on behind the scenes and I dont feel like going through 2K lines of code…, and I have hard time understanding documentation like always.
Here is the final code.
local function BanPlayer(userId: number, active: boolean)
local profile = PlayerProfileStore:LoadProfileAsync("Player_".. userId, "ForceLoad")
if not profile then return end
if not profile.Data.Ban then
profile.Data.Ban = {
active = false
}
end
profile.Data.Ban.Active = active
profile:Release()
end
that should work! obviously you might need to adjust this if you want to be able to ban people who have never played before, as you’re returning on the second line if the profile doesn’t exist
Oh, I forgot about that case. But won’t profile be returned still even if player never played before? Because when player joins I do pretty much the same thing.