Does anybody know how I would make a leaderboard using this? It seems that the commands are different than normal leaderboards.
EDITED: Solved my problem, I just created another player added function to run directly after the first was called.
Is anyone familiar force equiping/removing tools?
I would like for the characters tool to be forced-equipped when joining and forced-unequipped when leaving.
Equipping a particular tool essentially increases the players stats a set amount and removing the tool reduces the stats by the same set amount.
Currently if the player leaves the game with the tool equipped, they keep the stat increase, when re-joining and equipping the next time they get another stat boost.
I believe I need to add in the following script but I don’t know where because of the way profileservice loads profiles.
player.CharacterAdded:Connect(function(character)
local hum = character:WaitForChild("Humanoid")
hum:EquipTools()
end)
player.CharacterRemoving:Connect(function(character)
local hum = character:WaitForChild("Humanoid")
hum:UnequipTools()
end)
The profileservice PlayerAdded and PlayerRemoving functions:
local function PlayerAdded(player: Player)
local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if profile == nil then
player:Kick("Data issue, try again shortly. If issue persists, contact us!")
return
end
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Manager.Profiles[player] = nil
player:Kick("Data issue, try again shortly. If issue persists, contact us!")
end)
if player:IsDescendantOf(Players) == true then
Manager.Profiles[player] = profile
giveStats(player)
giveItems(player)
print("player data loaded")
else
profile:Release()
end
end
--loop through players
for _, player in ipairs(Players:GetPlayers()) do
task.spawn(PlayerAdded, player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerAdded:Connect(ToolsAdded)
**EDITED: added the line above ^^^
--player removed
Players.PlayerRemoving:Connect(function(player: Player)
local profile = Manager.Profiles[player]
if not profile then return end
profile:Release()
end)
Any help if greatly appreciated!
Does anyone know how I would convert an existing DataStore to ProfileService, or import DataStore saves to ProfileService? The structure for my DataStore usage is not the greatest; I save Kills, Deaths, and Rebirths, and a table that has the names of tycoon elements players buy in my game, but they are all saved via separate :SetAsync() calls in DataStore, and a lot of players have been reporting that their data was lost/corrupted, either reverting back to a previous version, or being lost completely, especially if they were disconnected/lost connection.
I’m sure this has been answered before in this thread, but there are 1000+ posts that I cannot possibly read all of them in a reasonable fashion
Changing data storage methods is often very challenging and risky. If it is an option for your game, wiping data would be easier.
If it’s not an option, you would have to make it so when a player joins that has the old data, their data would get placed in a profile. If this fails, kick them so they can try again. You need a method of knowing if a player’s data has been successfully converted. Then within the game you can just use the profile as you would usually.
Alternatively, if your game doesn’t have much player data, you can run a script from the command line that would change their data. You should shutdown your game while you do this, so no player data is corrupted.
Make sure to triple check everything!
Having a bit of a weird issue right now.
Im using ProfileService with ReplicaService, and Im getting the error Attempt to index nil with 'Replica'
, as if its set to nil, but it is not.
Code: (Pretty sure this is the exact same as the ProfileService example in ReplicaService)
profile:ListenToRelease(function()
profiles[player].Replica:Destroy() -- this is the line that errors
profiles[player] = nil
player:Kick()
end)
I tried doing print(player)
right before trying to destroy the Replica, and it prints fine. Nowhere in the code does profiles[player]
get set to nil, except in the snippet that I posted. What is the issue here?
EDIT: Nevermind, this is entirely my fault. There is a chance the profile gets released before the Replica gets created, if a player leaves the game fast enough. My bad
There’s a lot of data. Like, kills, deaths, and rebirths of each player, and then their base loads. Resetting is not an option
Here is a way you can do it:
- Add some sort of DataVersion integer to your profile template, and preferably set it to 0
- Load profile when joining
- If the DataVersion is 0, it means they are a new player
- Load the old datastore
- If data from old datastore ~= nil then convert data ie:
profile.Kills = oldData.Kills
and so on - If the data IS nil, skip the previous step
- Set DataVersion to 1
All done!
I am actually in the process of doing this as we speak, albeit the issues I am running into are pretty bad.
One issue I have been having is, when I try to load data from the player’s profile, all I get are “profile does not exist” errors and it doesn’t load any of the data.
I have been looking for solutions to this issue, and I have no come across anything.
Is there a safe way to load profiles for players who may be in a separate server already loaded? I got a system to allow mail to be sent to offline players, and I’m getting data like such
if receivingPlayerData then -- player is already in server
return receivingPlayerData
else
-- Use the load profile stuff to get their data based on receivingPlayerId
and then once the update is fired, and the player isn’t in the server, I release their data. And this all works fine, but this is from me testing just solo. I’m worried if a player tries to send mail to a friend, who may be playing in a different server, that it’s gonna try getting their data and cause issues for the other player?
Does anyone recommend a specific work around for this?
Make sure you have a working profile service implementation to begin with.
I would start creating profiles as if there’s no data to copy into them. When that works without errors, you can add the data copy code.
The error you get is most likely due to your code not correctly creating/loading the profiles. Probably unrelated to the data copy you want to do.
What ended up being the issue, it seems, is that ProfileService was getting called before it could fully load.
local active_session = loaded_data.MetaData.ActiveSession
local session_load_count = loaded_data.MetaData.SessionLoadCount
local session_owns_profile = false
if type(active_session) == "table" then
print(IsThisSession(active_session))
print(session_load_count, last_session_load_count)
session_owns_profile = IsThisSession(active_session) and session_load_count == last_session_load_count
end
(Line 1074: of the ProfileService Module)
I’ve got this issue where session_load_count
and last_session_load_count
will randomly not be equivalent causing the Profile to be released and the player to be kicked from the game. Does anyone know why this happens? What causes this to happen? It’s quite the issue since players will randomly get booted. Any help is appreciated.
I’m not sure what you mean with that, but be sure to double check for issues in studio and in real servers.
As far as I know it’s best to write a wrapper modulescript for profile service. In that module you should load the profiles, clean them up, etc. Then you can have functions like ‘incrementValue()’ that take a key, and increment it’s value (assuming integer values), ‘setValue()’, etc.
Doing it like this I’ve never had any issues with profile service.
Edit: I have figured why and got back the previous save data Thank you!
Hi! I was doing some internal testing previously and i’ve got a question about this situation - Changing the profile key and it wipes the whole previous key data
I have tried using ProfileVersionQuery on the previous key and there is no data on the old key anymore Might I ask is it a normal situation? Thank you!
Hello, Is there any way to get profiles without a player inside the game? without specifying a key? I wanted to use this for global leaderboards as it is very easy to use.
Using this was a breeze! I just got stuck on this part.
Definitely, you can make anything you wish. ProfileService is not fixed to something, that’s what I love.
Also, you can make stuff like Roblox Jailbreak’s Crew System with GlobalUpdates if that’s what you mean. If you want, however, to minimise the time taken for the updates (it’s generally a minute), you can set-up a messaging service connection that attempts to call the server which holds the other user and save their data (I’m guessing you are going to have users inside clans). Saving their data will speed up GlobalUpdates retrieving process since it’s going to retrieve it immediately after saving it. View the documentation too.
could you explain what happened as it doesn’t make any sense? ProfileService is a module script, therefore it won’t return (be given) to the script that required it until it has been executed at least once (code yield)
When profile service create an event to detect when an dataChanged?
I believe if you have it linked to an external value for displaying only (like leaderstats), you can checked when it’s changed that way without needing to require the module by using the .Changed event found on most values.
Awesome Module @loleris, However I had Encountered a Simple Problem,
So i want To Check when the player Profile is Fully Loaded, However I Can’t Find a way To do it, Rather Than Checking if a Profile is in The Profiles Table, So if There is anyway you could help me about That,
That Would be Cool