Saving Progress With NPC In Data

In my game, there is a “stamina” bar called “chi”, which every move of the game costs a certain amount of chi.

I made an NPC where, if you have the required amount of gems, you can keep buying +25 chi until you reach 300 total chi.

To avoid the use of DataStore, I made my NPC that increases your chi check if you have more than 300 chi or not (if so, then it’s already mastered). I want to make a gamepass where you get +50 chi. The starter amount of chi is 200, and, if the player buys the gamepass, they’ll be starting with 250, being unable to buy +25 chi 4 times.

I want to save in data the amount of times the player has bought chi, but I don’t know yet how I should do that. Anyone has any idea of how I should try to do this? My main issue is with the way I would have to organize all that.

I know this is a bit overkill for your level but, I’d recommend using EasyProfile which is part of the canary suite by @2jammers which essentially is just a Profile Service wrapper. I recommend reading the documentation/guide for further understanding

I couldn’t really indent it properly because I can’t do Tab

-- ... require the module

local ProfileKey = "GeneralPlayerData" -- an unique key to store the data on
local ProfileTemplate = {

TheNPC = { -- the npc data you're referring to for each player

AmountBoughtChi = 0

}

} -- the structure of the profile store
local PlayerProfileStore = EasyProfile.CreateProfileStore(ProfileKey, ProfileTemplate)

local function OnPlayerAdded(player: Player)

-- :LoadProfileAsync(string|Player key, boolean? reconcileData, string? profileClaimedHandler)
PlayerProfileStore:LoadProfileAsync(player, true, "ForceLoad"):After(function(success, playerProfile)
if not success then
return
end

-- get the profile data and do something with it
local ProfileData = playerProfile:GetProfileData()

-- to get the npc data:
local NPCData = ProfileData.TheNPC
local AmountBoughtChi = NPCData.AmountBoughtChi

-- to set the npc data:
ProfileData.TheNPC.AmountBoughtChi += 1 -- increase the chi whenever the player joins and successfully loads the data

end)

end

I was mainly worried about how I should organize the progression with the NPC to save it efficiently, and I got also an introduction to a new data storing system. Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.