How to made Stats adding overtime with Profile Service

I just started to learning Profile Service and I don’t know how to make stats adding overtime with Profile Service. I tried this script below but it doesnt work at all. Can someone help me please?

local amount = 150
local amount2 = 200

local giveTime = 15

--//Services
local Replicated = game:GetService('ReplicatedStorage')
local Players = game:GetService("Players")

--//Required modules
local PlayerDataManager = require(game:GetService("ServerScriptService").PlayerDataManager)

while task.wait(giveTime) do
	for _,plr in pairs(Players:GetChildren()) do

		local stats = plr:FindFirstChild('leaderstats')
		
		local SoulStats = PlayerDataManager:GetPlayerProfile(plr)
		
		PlayerDataManager:GetPlayerProfile(plr):andThen(function(Profile)
			local stats = Profile.Data.Souls
			if stats < 175000 then
				stats += amount
			elseif stats.Souls.Value >= 175000 then
				stats += amount2
			end
		end)
	end
end
2 Likes

I believe this is the issue.
stats has the value of Profile.Data.Souls, but is not linked to it. Subsequently, you can update the value of stats without affecting Profile.Data.Souls (and likewise can update the value of Profile.Data.Souls without updating the value of stats).

The simplest fix would be to write out in full Profile.Data.Souls in place of stats in the places where you are adding amount/amount2 (lines 23 and 25)

1 Like

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