Hey all! I’m using the ProfileService module to save my player data. However, for whatever reason my script isn’t properly updating the player’s data.
GiveExp Script
local GiveExp = {}
local datastore = require(game.ServerScriptService.Modules.Data.DataGetter)
function GiveExp:giveExp(player, amount, source)
local playerData = datastore:Get(player)
local playerExp = playerData.Experience
local playerLevel = playerData.Level
local requiredExp = 20 + ((playerLevel * 2) ^ 1.9)
playerExp = playerExp + amount
if playerExp >= requiredExp then
playerExp = 0
playerLevel = playerLevel + 1
end
end
return GiveExp
DataGetter
local ProfileService = require(script.Parent.ProfileService)
local ReplicaService = require(script.Parent.Parent.ReplicaService)
local ProfileStore = ProfileService.GetProfileStore(
"Player",
{
--// CURRENCY
Trimmings = 0;
Shards = 0;
--// STATS
GrassCut = 0;
Level = 0;
Experience = 0;
BossKills = 0;
--// MISCELLANEOUS
UpgradesOwned = {};
Health = 100;
Sprint = 5;
}
}
)
local Profiles = {}
game.Players.PlayerRemoving:Connect(function(whoLeft)
if Profiles[whoLeft] then
Profiles[whoLeft]:Release()
end
end)
game.Players.PlayerAdded:Connect(function(whoJoined)
local profile = ProfileStore:LoadProfileAsync("Player_"..whoJoined.UserId, "ForceLoad")
if profile then
--//Replicates data to client
game.ServerStorage.Events.RequestSaveData.Event:Connect(function(player)
if player == whoJoined then
local StatsMenuReplica = ReplicaService.NewReplica({
ClassToken = ReplicaService.NewClassToken("StatsMenuReplica_"..whoJoined.UserId),
Data = {Trimmings = profile.Data.Trimmings, Level = profile.Data.Level, Experience = profile.Data.Experience, BossKills = profile.Data.BossKills, GrassCut = profile.Data.GrassCut, Shards = profile.Data.Shards, BestMower = profile.Data.BestMower, MowerImage = game.ServerStorage.Mowers[profile.Data.BestMower]:GetAttribute("Image")},
Replication = whoJoined
})
end
end)
--//
profile:ListenToRelease(function()
Profiles[whoJoined] = nil
whoJoined:Kick("Data was released.")
end)
if whoJoined:IsDescendantOf(game.Players) then
Profiles[whoJoined] = profile
else
profile:Release()
end
else
whoJoined:Kick("Error loading data.")
end
end)
local DataGetter = {}
function DataGetter:Get(player)
local profile = Profiles[player]
if profile then
return profile.Data
end
end
return DataGetter
I have another script in the game which updates the player’s data, but that one is a string. I’m not sure why it’s not working with numbers, since I’m not very good with data stuff. Any help is appreciated, thanks!