I’m making a game and there’s a level up system in it. You can unlock different teams using the exp you gain via playing the game. There’s also ranks for different teams. Do I use the same datastore to save the total amount of exp and the amount of exp for each team, or I make different DataStores for different teams and one DataStore to save the total amount of exp?
You should use one datastore with multiple tables to store all your player information, multiple datastores is a huge and unnecessary struggle.
I as a scripter, I never trust DataStores of Roblox itself, I recommend using ProfileService since I use it IMO
I connected it to a discord webhook so everytime a player joins and leaves it sends a message to the channel. Can that prevent data loss?
never, you can just use ProfileService or DataStore2 those modules are saving-loss proof
I agree with Ferb. I honestly find ProfileService much easier and more efficient. But please don’t use discord web hook that won’t do anything at all. You can probably just use it to see peoples data but DONT MAKE IT FOR SAVING.
aight thanks for the reply everyone
So from my understanding, I setup ProfileService and make multiple tables for different teams. Can anyone give me an example on how to setup a table for ProfileService?
its literally on the topic, I gave its just basically make a new profile for the game and load it in within the player added event
Example:
-- ProfileTemplate table is what empty profiles will default to.
-- Updating the template will not include missing template values
-- in existing player profiles!
local ProfileTemplate = {
Cash = 0,
Items = {},
LogInTimes = 0,
}
----- Loaded Modules -----
local ProfileService = require(game.ServerScriptService.ProfileService)
----- Private Variables -----
local Players = game:GetService("Players")
local GameProfileStore = ProfileService.GetProfileStore(
"PlayerData",
ProfileTemplate
)
local Profiles = {} -- [player] = profile
----- Private Functions -----
local function GiveCash(profile, amount)
-- If "Cash" was not defined in the ProfileTemplate at game launch,
-- you will have to perform the following:
if profile.Data.Cash == nil then
profile.Data.Cash = 0
end
-- Increment the "Cash" value:
profile.Data.Cash = profile.Data.Cash + amount
end
local function DoSomethingWithALoadedProfile(player, profile)
profile.Data.LogInTimes = profile.Data.LogInTimes + 1
print(player.Name .. " has logged in " .. tostring(profile.Data.LogInTimes)
.. " time" .. ((profile.Data.LogInTimes > 1) and "s" or ""))
GiveCash(profile, 100)
print(player.Name .. " owns " .. tostring(profile.Data.Cash) .. " now!")
end
local function PlayerAdded(player)
local profile = GameProfileStore:LoadProfileAsync(
"Player_" .. player.UserId,
"ForceLoad"
)
if profile ~= nil then
profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
profile:ListenToRelease(function()
Profiles[player] = nil
-- The profile could've been loaded on another Roblox server:
player:Kick()
end)
if player:IsDescendantOf(Players) == true then
Profiles[player] = profile
-- A profile has been successfully loaded:
DoSomethingWithALoadedProfile(player, profile)
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()
end
end
----- Initialize -----
-- In case Players have joined the server earlier than this script ran:
for _, player in ipairs(Players:GetPlayers()) do
coroutine.wrap(PlayerAdded)(player)
end
----- Connections -----
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player)
local profile = Profiles[player]
if profile ~= nil then
profile:Release()
end
end)
Tried this, but it doesn’t work. I’ll try it again tomorrow.
are you sure that you are saving values and by saving values:
profile.Data.Coins = 232323232 -- any?
it worked for me did you have API Services enabled and can you tell me what is the output when you enter the game
It works now. I’m now working on the timedelay part where it gives you 1 credit every 30 seconds.