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)
I don’t have permission can you please open it
Oh sorry, I just distributed it now.
And… alao you can call GetProfile like this.
local profile = ProfileServiceManager:GetProfile(plr)
while profile == nil do
profile = ProfileServiceManager:GetProfile(plr)
end
Because, GetProfile function doesn’t access to the database directly. It returns players profile in the dictionary.
Also, Add this code in your game.
game.Players.PlayerRemoving:Connect(function(plr)
local profile = ProfileServiceManager:GetProfile(plr)
while profile == nil do
profile = ProfileServiceManager:GetProfile(plr)
end
-- Before player removing code like 'give panalty'
profile:Release()
end)
I’ll post a more accurate tutorial when I get home. And I’ll put the link here. You can read it if you need.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.