ProfileService Need Help

Okay well this is interesting, first time using Profile Service and watched two tutorials on it. Here is the issue I am encountering.

Issue: No profile is being found upon changing cash or any value

Module Script for changing Cash

local module = {}

module.Profiles = {}
function module:AdjustCash(player, amount)
	local profile = module.Profiles[player]
	if not profile then warn("no profile") return end
	profile.Data.Cash += amount
	player.leaderstats.Cash.Value += profile.Data.Cash
end
return module

–The debugging script (Server Script)

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local PlayerData = require(ServerScriptService.PlayerData.Manager)

while true do
	for _, player in pairs(Players:GetPlayers()) do
		PlayerData.AdjustCash(player, 5)
	end
	task.wait(1)
end

And Finally my Data Server Script

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local Template = require(script.Parent.Template)
local ProfileService = require(ServerScriptService.Libs.ProfileService)
local Manager = require(script.Parent.Manager)

--Set to Live when publishing
local ProfileStore = ProfileService.GetProfileStore("Live", Template)

local function GiveLeaderstats(player: Player)
	local profile = Manager.Profiles[player]
	if not profile then return end
	
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local Cash = Instance.new("NumberValue",leaderstats)
	Cash.Name = "Cash"
	Cash.Value = profile.Data.Cash
	
	local Level = Instance.new("NumberValue", leaderstats)
	Level.Name = "Level"
	Level.Value = profile.Data.Level
end

local function PlayerAdded(player: Player)
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
	if profile == nil then
		player:Kick("An error went wrong loading your data. Contact us if the issue persists.")
		return
	end
	
	-- Player Profile was loaded Successfully
	profile:AddUserId(player.UserId)
	profile:Reconcile()
	profile:ListenToRelease(function()
		Manager.Profiles[player] = nil
		player:Kick("An error went wrong loading your data. Contact us if the issue persists.")
	end)
	
	if player:IsDescendantOf(Players) == true then
		Manager.Profiles[player] = profile
		GiveLeaderstats(player)
	else
		profile:Release()
	end
end

for _, player in ipairs(Players:GetPlayers()) do
	task.spawn(PlayerAdded, player)
end

Players.PlayerAdded:Connect(PlayerAdded)

Players.PlayerRemoving:Connect(function(player: Player)
	local profile = Manager.Profiles[player]
	if not profile then return end
	profile:Release()
end)

It seems to break after i added my function for Adjusting cash, although i highly doubt this can be the issue since the other tutorial i used my profile was never found, I have played both in Roblox and Roblox Studio and still receive the “no profile” error

Edit: Studio Access to API Services is enabled also.

The function in the module is defined using a colon.

But in the script, you are calling it with a period. This doesn’t cause an error, but will mean that the first argument becomes self, which isn’t what you want.

You should change one of the two so that they match (either define it using a period or call it with a colon). Defining this function using a colon isn’t necessary, as the self variable isn’t used, but it comes down to preference.

Ah i normally use colons cause thats what i always used ever since i learned using modules, fixed the error I was having thank you!

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