ProfileService Not Creating Instances and Getting "instance is not a valid member of..." Errors

I recently installed ProfileService for DataStores and it’s not working properly. I’ve searched through the DevForum and all related posts with solution are locked and I do not understand how to fix the issue.

The first error I get is " ServerScriptService.DataStore.Data:54: attempt to index nil with ‘MetPete’", and then everything breaks because other scripts cannot find certain instances because they were never created due to the error.

Here’s the module with the template:

local module = {
	Coins = 0,
	Gems = 0,
	
	Level = 0,
	Exp = 0,
	
	QuestNum = 1,
	QuestInProgress = false,
	QuestStats = {
		MetPete = false,
		SticksCollected = 0,
		BoughtWire = false,
	},
	
	Boosts = {
		CoinsBoosts = 0,
		CoinsBoostsTime = 0,
		GemsBoosts = 0,
		GemsBoostsTime = 0,
	},
	
	Settings = {
		Music = true,
		SFX = true,
		World = true,
		Notifications = true,
		ShowBoosts = true,
		ShowLevel = true,
		LevelDisplay = "Round",
		ShowTime = true,
		TimeFormat = "24H",
		Weather = true,
		RealisticLighting = true,
		FancyTerrain = true,
	},
	
	Items = {
		FishingWire = 0,
		Trails = {
			RedTrail = 0,
			OrangeTrail = 0,
			YellowTrail = 0,
			LimeTrail = 0,
			GreenTrail = 0,
			CyanTrail = 0,
			BlueTrail = 0,
			PinkTrail = 0,
			PurpleTrail = 0,
			BlueFadeTrail = 0,
		},
	},
	
	Updates = {
		Tutorial = false,
		BETA = false,
	},
	
	Codes = {
		Code1 = false,
		Code2 = false,
		Code3 = false,
	},
}

return module

Here’s the datastore script:

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

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

--Always keep string as "Data" to no wipe Player data!!!--

local ProfileStore = ProfileService.GetProfileStore("Data", Template)

local function GiveLeaderstats(player: Player)
	local Profile = Manager.Profiles[player]
	if not Profile then return end
	
	--Leaderstats--
	
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local Level = Instance.new("NumberValue", leaderstats) 
	Level.Name = "Level" 
	Level.Value = Profile.Data.Level

	local Exp = Instance.new("NumberValue", leaderstats)
	Exp.Name = "Exp" 
	Exp.Value = Profile.Data.Exp

	local Coins = Instance.new("NumberValue", leaderstats)
	Coins.Name = "Coins" 
	Coins.Value = Profile.Data.Coins

	local Gems = Instance.new("NumberValue", leaderstats)
	Gems.Name = "Gems" 
	Gems.Value = Profile.Data.Gems
	
	--Quests--

	local QuestNum = Instance.new("NumberValue", player)
	QuestNum.Name = "QuestNum"
	QuestNum.Value = Profile.QuestNum

	local QuestInProgress = Instance.new("BoolValue", player)
	QuestInProgress.Name = "QuestInProgress"
	QuestInProgress.Value = Profile.QuestInProgress
	
	--Quest Stats--

	local QuestStats = Instance.new("Folder", player)
	QuestStats.Name = "QuestStats"
	
	local MetPete = Instance.new("BoolValue", QuestStats)
	MetPete.Name = "MetPete"
	MetPete.Value = Profile.QuestStats.MetPete

	local SticksCollected = Instance.new("NumberValue", QuestStats)
	SticksCollected.Name = "SticksCollected"
	SticksCollected.Value = Profile.QuestStats.SticksCollected

	local BoughtWire = Instance.new("BoolValue", QuestStats)
	BoughtWire.Name = "BoughtWire"
	BoughtWire.Value = Profile.QuestStats.BoughtWire
	
	--Boosts--
	
	local Boosts = Instance.new("Folder", player)
	Boosts.Name = "Boosts"

	local CoinsBoosts = Instance.new("NumberValue", Boosts)
	CoinsBoosts.Name = "CoinsBoosts"
	CoinsBoosts.Value = Profile.Data.Boosts.CoinsBoosts

	local CoinsBoostTime = Instance.new("NumberValue")
	CoinsBoostTime.Name = "Time"
	CoinsBoostTime.Value = Profile.Data.Boosts.CoinsBoostsTime

	local GemsBoosts = Instance.new("NumberValue")
	GemsBoosts.Name = "GemsBoosts"
	GemsBoosts.Value = Profile.Data.Boosts.GemsBoosts

	local GemsBoostTime = Instance.new("NumberValue")
	GemsBoostTime.Name = "Time"
	GemsBoostTime.Value = Profile.Data.Boosts.GemsBoostsTime
	
	--Items--
	
	local Items = Instance.new("Folder", player)
	Items.Name = "Items" 

	local FishingWire = Instance.new("NumberValue", Items)
	FishingWire.Name = "FishingWire" 
	FishingWire.Value = Profile.Items.FishingWire

	local Trails = Instance.new("Folder", Items)
	Trails.Name = "Trails"

	local RedTrail = Instance.new("NumberValue", Trails)
	RedTrail.Name = "Red"
	RedTrail.Value = Profile.Items.Trails.RedTrail

	local OrangeTrail = Instance.new("NumberValue", Trails)
	OrangeTrail.Name = "Orange"
	OrangeTrail.Value = Profile.Items.Trails.OrangeTrail

	local YellowTrail = Instance.new("NumberValue", Trails)
	YellowTrail.Name = "Yellow"
	YellowTrail.Value = Profile.Items.Trails.YellowTrail

	local LimeTrail = Instance.new("NumberValue", Trails)
	LimeTrail.Name = "Lime"
	LimeTrail.Value = Profile.Items.Trails.LimeTrail

	local GreenTrail = Instance.new("NumberValue", Trails)
	GreenTrail.Name = "Green"
	GreenTrail.Value = Profile.Items.Trails.GreenTrail

	local CyanTrail = Instance.new("NumberValue", Trails)
	CyanTrail.Name = "Cyan"
	CyanTrail.Value = Profile.Items.Trails.CyanTrail

	local BlueTrail = Instance.new("NumberValue", Trails)
	BlueTrail.Name = "Blue"
	BlueTrail.Value = Profile.Items.Trails.BlueTrail

	local PurpleTrail = Instance.new("NumberValue", Trails)
	PurpleTrail.Name = "Purple"
	PurpleTrail.Value = Profile.Items.Trails.PurpleTrail

	local PinkTrail = Instance.new("NumberValue", Trails)
	PinkTrail.Name = "Pink"
	PinkTrail.Value = Profile.Items.Trails.PinkTrail

	local BlueFadeTrail = Instance.new("NumberValue", Trails)
	BlueFadeTrail.Name = "BlueFade"
	BlueFadeTrail.Value = Profile.Items.Trails.BlueFade
	
	--Updates--
	
	local Updates = Instance.new("Folder", player)
	Updates.Name = "Updates"

	local Tutorial = Instance.new("BoolValue", Updates)
	Tutorial.Name = "Tutorial"
	Tutorial.Value = Profile.Updates.Tutorial

	local BETA = Instance.new("BoolValue", Updates)
	BETA.Name = "BETA"
	BETA.Value = Profile.Updates.BETA
	
	--Codes--
	
	local Codes = Instance.new("Folder", player)
	Codes.Name = "Codes"

	local Code1 = Instance.new("BoolValue", Codes)
	Code1.Name = "Code1"
	Code1.Value = Profile.Codes.Code1

	local Code2 = Instance.new("BoolValue", Codes)
	Code2.Name = "Code2"
	Code2.Value = Profile.Codes.Code2

	local Code3 = Instance.new("BoolValue", Codes)
	Code3.Name = "Code3"
	Code3.Value = Profile.Codes.Code3
end

local function PlayerAdded(player: Player)
	local Profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
	if Profile == nil then
		player:Kick("Player data issue, please try again. If this issue persists, please contact a member of staff.")
		return
	end
	
	Profile:AddUserId(player.UserId)
	Profile:Reconcile()
	Profile:ListenToRelease(function()
		Manager.Profiles[player] = nil
		player:Kick("Player data issue, please try again. If this issue persists, please contact a member of staff.")
	end)
	
	if player:IsDescendantOf(Players) == true then
		Manager.Profiles[player] = Profile
		GiveLeaderstats(player)
	else
		Profile:Release()
	end
end

for _, player in 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)

I’m kind of an amateur scripter and only used a tutorial therefore I don’t understand how to fix the issue. If someone could please explain it or give an example I would really appreciate it!

1 Like

You have to use Profile.Data.QuestStats.MetPete.
Same with all the other times you want to access the player’s data.

1 Like

Now I get even more errors when I do that.

1 Like

If I’m getting the error at “MetPete” that means everything before it should work, which is does, and when tested after removing the “MetPete” instance, the instance right after it didn’t work either meaning anything after “QuestStats” folder doesn’t work, I can’t seem to figure out why…

1 Like

Hold on, adding .Data did work I just have to figure something else out.

1 Like

Thanks, it’s just the only issue is “not a valid member of” errors which can be fixed with :WaitForChild() which is kinda tedious.

2 Likes

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