How to store ProfileService With Alot of Data to Store

local module = {
	Abilities = {
		BaseAbility = "Air",
		Slot1 = {
			AbilityName = "None",
			ActivationType = "Punch",
			Knockback = 5,
			Shape = "Ball",
			Speed = "None"
		},
		Slot2 = {
			AbilityName = "Smash",
			ActivationType = "Projectile",
			Knockback = 5,
			Shape = "Ball",
			Speed = "None"
		},
		Slot3 = {
			AbilityName = "None",
			ActivationType = "Punch",
			Knockback = 5,
			Shape = "Ball",
			Speed = "None"
		},
		Slot4 = {
			AbilityName = "None",
			ActivationType = "Punch",
			Knockback = 5,
			Shape = "Ball",
			Speed = "None"
		},
		Slot5 = {
			AbilityName = "None",
			ActivationType = "Punch",
			Knockback = 5,
			Shape = "Ball",
			Speed = "None"
		},
		Slot6 = {
			AbilityName = "None",
			ActivationType = "Punch",
			Knockback = 5,
			Shape = "Ball",
			Speed = "None"
		},
	}
}
return module

There is alot of table in table and i don’t want to add every single one with .AddCash .AddDiamond is there is a fast effective way to do it?

2 Likes

You want to store the items? or cash and diamond

store the tables or module that I posted

It will be more convenient if you create a module script that processes a large number of tables and apply it to the profile service. By the way, why are you trying to save the module script?

Nononono That is the template for ProfileService

If AbilityName, ActivationType, Knockback, Shape, or Speed ​​change, you have no choice but to save it that way. However, if you can change the data with “Punch” or “Smash”, it will be more efficient to change it. If you need to use that profile template, you can create a module as mentioned earlier and reduce repetitive code with the getSlot and saveSlot functions. Alternatively, you can save it in Array format rather than Dictionary format, but this method is not recommended as it contains “None”.

What should I do to fix these then?

Abilities = {
	BaseAbility = "Air",
	Slot1 = {
		AbilityName = "None",
		ActivationType = "Punch",
		Knockback = 5,
		Shape = "Ball",
		Speed = "None"
	},
	Slot2 = {
		AbilityName = "Smash",
		ActivationType = "Projectile",
		Knockback = 5,
		Shape = "Ball",
		Speed = "None"
	},
	Slot3 = {
		AbilityName = "None",
		ActivationType = "Punch",
		Knockback = 5,
		Shape = "Ball",
		Speed = "None"
	},
	Slot4 = {
		AbilityName = "None",
		ActivationType = "Punch",
		Knockback = 5,
		Shape = "Ball",
		Speed = "None"
	},
	Slot5 = {
		AbilityName = "None",
		ActivationType = "Punch",
		Knockback = 5,
		Shape = "Ball",
		Speed = "None"
	},
	Slot6 = {
		AbilityName = "None",
		ActivationType = "Punch",
		Knockback = 5,
		Shape = "Ball",
		Speed = "None"
	},
}

You are saving this, right?

Yes! that was the thing i’m trying to do maybe more

You can update that data like this

profile.Data[Abilities.Slot1.Knockback] = 10

And… are you looking for a way to make this process easier?

How to add that stats when i’m in localscript?

You means, how to save data in localscript?

I mean how to add stats via local script because i’m trying

You mean add data to your slot table during runtime?

I mean… yeah i want to do that

detect event in localscript => update slot table?

OH MY GOD here take a look


local Template = require(script.Parent.Data.Data.Template)
local DataStore2 = require(script.Parent.Data.ProfileService)
local Manager = require(script.Parent.Data.Manager)

ProfileStore = DataStore2.GetProfileStore("Data", Template)
game:GetService("ReplicatedStorage"):WaitForChild("Remote").OnServerEvent:Connect(function(plr,Place,Value,First,Second,Third,Four,Five)
	if Place then
		local profile = ProfileStore:LoadProfileAsync("Player_"..plr.UserId)
		Place.Value = Value
		if First ~= nil and Second == nil and Third == nil and Four == nil and Five == nil then
			profile.Data[First] = Value
		end
		if Second ~= nil and Third == nil and Four == nil and Five == nil then
			profile.Data[First][Second] = Value
		end
		if Third ~= nil and Four == nil and Five == nil then
			profile.Data[First][Second][Third] = Value
		end
		if Four ~= nil and Five == nil then
			profile.Data[First][Second][Third][Four] = Value
		end
		if Five ~= nil then
			profile.Data[First][Second][Third][Four][Five] = Value
		end
	end
end)

I see… You means, that code is complicated and also doesn’t work.

Try this module script which I made. I summarize the profile service functions in here.

It is not recommended to call LoadProfileAsync frequently. Also, in the code above, data is being updated and not saved.

local ProfileServiceManager = game.ServerScriptService.ProfileServiceManager

game:GetService("ReplicatedStorage"):WaitForChild("Remote").OnServerEvent:Connect(function(plr,Place,Value,First,Second,Third,Four,Five)
	if Place then
		local profile = ProfileServiceManager:GetProfile(plr)
		Place.Value = Value
		if First ~= nil and Second == nil and Third == nil and Four == nil and Five == nil then
			profile.Data[First] = Value
            ProfileServiceManager:UpdateProfile(plr, First, profile.Data[First])
		end
		if Second ~= nil and Third == nil and Four == nil and Five == nil then
			profile.Data[First][Second] = Value
            ProfileServiceManager:UpdateProfile(plr, First, profile.Data[First])
		end
		if Third ~= nil and Four == nil and Five == nil then
			profile.Data[First][Second][Third] = Value
            ProfileServiceManager:UpdateProfile(plr, First, profile.Data[First])
		end
		if Four ~= nil and Five == nil then
			profile.Data[First][Second][Third][Four] = Value
            ProfileServiceManager:UpdateProfile(plr, First, profile.Data[First])
		end
		if Five ~= nil then
			profile.Data[First][Second][Third][Four][Five] = Value
            ProfileServiceManager:UpdateProfile(plr, First, profile.Data[First])
		end
        ProfileServiceManager:SaveProfile(plr)
	end
end)