Player data being wiped with ProfileService

Hello,

I am currently doing scripting work for a game, UGC Island.

However following a recent update, players data is wiped upon leaving. I’m using ProfileService and nothing has changed in terms of how the profiles are being saved and loaded, and this is the only new script that was added.

local ServerScriptService = game:GetService("ServerScriptService")
local ProfileHelper = require(ServerScriptService.Modules.ProfileHelper)
local redeemRem = game.ReplicatedStorage:WaitForChild('redeemInventoryItem')
local updateRem = game.ReplicatedStorage:WaitForChild("updateInventory")
local updateSpins = game.ReplicatedStorage:WaitForChild("updateSpins")
local Prompter = require(ServerScriptService.Modules.Prompter)
local rewardRem = game.ReplicatedStorage:WaitForChild("Show50Spins")

local function AddToArray(t, value, duration)
	table.insert(t, value)
	local m = #t
	task.delay(duration, function()
		local l = #t
		for i = 1, math.min(m, l) do
			if t[i] == value then 
				table.remove(t, i)
				break
			end
		end
	end)
end

local inCooldown = {}

redeemRem.OnServerEvent:Connect(function(player, itemID, timeWon)
	itemID = tonumber(itemID)
	timeWon = tonumber(timeWon)
	local inventory = ProfileHelper.GetInventory(player)
	
	if inventory then
		if not table.find(inCooldown, player.Name) then
			AddToArray(inCooldown, player.Name, 1.5)
			for i, item in inventory do
				if item.ID == itemID then
					if item.TimeWon - timeWon < 5 then
						if item.ID == Prompter.ugcID then
							table.remove(ProfileHelper.GetInventory(player), i)
							Prompter.PromptUGC(player, itemID)
							updateRem:FireClient(player, ProfileHelper.GetInventory(player))
							break
						else
							table.remove(ProfileHelper.GetInventory(player), i)
							ProfileHelper.AddSpins(player, 50)
							rewardRem:FireClient(player)
							updateSpins:FireClient(player, ProfileHelper.GetSpins(player))
							updateRem:FireClient(player, ProfileHelper.GetInventory(player))
							break
						end
					end
				end
			end
		end
	end
end)

Is this something related to Roblox, or am I an idiot? If anyone could help I’d greatly appreciate it :slight_smile:

2 Likes

Hmmm, not sure.

I would look at this script though, quick example of how to save data with profile service.

local ProfileService = require(game.ServerScriptService.ProfileService)
local player = game.Players.LocalPlayer

local profile = ProfileService.GetProfile(player)
local moneyValue = player:WaitForChild("leaderstats"):WaitForChild("Money")
local spinsValue = player:WaitForChild("leaderstats"):WaitForChild("Spins")

-- Save money and spins when the player leaves
game:BindToClose(function()
    profile.Money = moneyValue.Value
    profile.Spins = spinsValue.Value
    profile:Release()
end)

-- Load money and spins when the player joins
profile:Reconcile()
moneyValue.Value = profile.Money or 0
spinsValue.Value = profile.Spins or 0

This is just an example, not a fix to your script. Would look at it thoughl. Don’t know if it will help.