Problems with getting data using ProfileService

Hello!

Recently i started to research more about the ProfileService module and I’ve recently ran into an error. I can’t seem to get info that should be stored in the profile even though it prints it out in the output ( as seen below ). I might be stupid but i cant really think of any reason why this could happen :sweat_smile:

Here’s the code that should get data from a profile

function pdh:Get(plr: Player, key: string) : {}
	local profile = getProfile(plr)
	print(profile.Data)
	assert(profile.Data[key], string.format("Data does not exist for key %s", key))
	
	return profile.Data[key]
end

( value exists in the default data table but cant be found??? )

What are you passing in as the key?

I pass the string “Combat”

here’s the line

pdh:Get(plr, "Combat") --plr is the player instance

It seems to be an issue with the getProfile() function then. It likely isn’t returning the player’s data.

You can check this with a simple guard clause after you call the function:

EDIT: Clearly not the issue lol. Let me think on that a minute.

1 Like

I think I got it.

assert checks if the given value is false or nil. In this case, profile.Data["Combat"] is false, which is why it throws the error.

I don’t know of a way around this other than just getting rid of the assert line. You could do extra checks like this:

if not profile.Data then return end

Or

if not profile.Data then error("Message to error") end

EDIT: To check the value directly, you could do something like this:

if profile.Data[key] == nil then error("Message to error") end
1 Like

Oh! i never knew that assert also checks if the output is false… Well, everything works good now, thanks!

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