Attempt to connect failed: Passed value is not a function - Studio

I keep getting the error:
Attempt to connect failed: Passed value is not a function - Studio
and it only started showing up after editing this script so the error is from the script below, I just don’t know from where:

local ProfileTemplate = {
	Leaderstats = {Coins = 0, Gems = 0, Level = 0, Exp = 0},
	
	Quests = {QuestNum = 0, MetPete = false, SticksCollected = 0, BoughtWire = false},
	
	Misc = {Code1 = false, Code2 = false, Code3 = false, TimePlayed = 0, DateJoined = 0, VIPRewardTimer = 0},
	
	Settings = {SFX = 1, World = 1, Music = 1, GraphicsQuality = 3, RealisticLighting = true, DayNightCycle = true, Weather = true, ShowLevel = true, ShowTime = true, LevelDisplay = 1, TimeFormat = 1, Notifications = true, NotificationSounds = true, ShowOtherCosmetics = true, GuidingArrows = true, DialogueSpeed = 4.5},
	
	Items = {
		--Items--
		
		FishingWire = 0,
		WateringCan = 0,
		Fertilizer = 0,
		Shovel = 0,
		
		--Trails & Effects--
		
		TrailRed = 0,
		TrailRedEquipped = false,
		TrailOrange = 0,
		TrailOrangeEquipped = false,
		TrailYellow = 0,
		TrailYellowEquipped = false,
		TrailLime = 0,
		TrailLimeEquipped = false,
		TrailGreen = 0,
		TrailGreenEquipped = false,
		TrailCyan = 0,
		TrailCyanEquipped = false,
		TrailBlue = 0,
		TrailBlueEquipped = false,
		TrailPurple = 0,
		TrailPurpleEquipped = false,
		TrailPink = 0,
		TrailPinkEquipped = false,
		TrailVIP = 0,
		TrailVIPEquipped = false,

		SparklesRed = 0,
		SparklesRedEquipped = false,
		SparklesOrange = 0,
		SparklesOrangeEquipped = false,
		SparklesYellow = 0,
		SparklesYellowEquipped = false,
		SparklesLime = 0,
		SparklesLimeEquipped = false,
		SparklesGreen = 0,
		SparklesGreenEquipped = false,
		SparklesCyan = 0,
		SparklesCyanEquipped = false,
		SparklesBlue = 0,
		SparklesBlueEquipped = false,
		SparklesPurple = 0,
		SparklesPurpleEquipped = false,
		SparklesPink = 0,
		SparklesPinkEquipped = false,
		SparklesVIP = 0,
		SparklesVIPEquipped = false,
	}
}

----- Loaded Modules -----

local ProfileService = require(game.ServerScriptService.ProfileService.ProfileService)

----- Private Variables -----

local Players = game:GetService("Players")

local ProfileStore = ProfileService.GetProfileStore("PlayerData", ProfileTemplate)

local Profiles = {} -- [Player] = Profile

local function DoSomethingWithALoadedProfile(Player, Profile)
	
	--Set Value----------------------------------------------------------------
	
	local Leaderstats = Player.Leaderstats
	local QuestStats = Player.QuestStats
	local Codes = Player.Codes
	local Items = Player.Items
	local Trails = Items.Trails
	local Effects = Items.Effects
	local Settings = Player.Settings
	
	--Leaderstats--
	
	Leaderstats.Coins.Value = Profile.Data.Leaderstats.Coins
	Leaderstats.Gems.Value = Profile.Data.Leaderstats.Gems
	Leaderstats.Level.Value = Profile.Data.Leaderstats.Level
	Leaderstats.Exp.Value = Profile.Data.Leaderstats.Exp

	--Quests--

	Player.QuestNum.Value = Profile.Data.Quests.QuestNum
	QuestStats.MetPete.Value = Profile.Data.Quests.MetPete
	QuestStats.SticksCollected.Value = Profile.Data.Quests.SticksCollected
	QuestStats.BoughtWire.Value = Profile.Data.Quests.BoughtWire

	--Misc--
	
	Codes.Code1.Value = Profile.Data.Misc.Code1
	Codes.Code2.Value = Profile.Data.Misc.Code2
	Codes.Code3.Value = Profile.Data.Misc.Code3
	
	Player.Stats.TimePlayed.Value = Profile.Data.Misc.TimePlayed
	Player.Stats.DateJoined.Value = Profile.Data.Misc.DateJoined
	Player.VIPRewardTimer.Value = Profile.Data.Misc.VIPRewardTimer

	--Settings--

	for _, Setting in ipairs(Settings:GetChildren()) do
		if Setting:IsA("IntValue") or Setting:IsA("BoolValue") then
			Setting.Value = Profile.Data.Settings[Setting.Name]
		end
	end

	--Items--
	
	Items.FishingWire.Value = Profile.Data.Items.FishingWire
	Items.WateringCan.Value = Profile.Data.Items.WateringCan
	Items.Fertilizer.Value = Profile.Data.Items.Fertilizer
	Items.Shovel.Value = Profile.Data.Items.Shovel
	
	for _, Trail in ipairs(Trails:GetChildren()) do
		if Trail:IsA("IntValue") then
			Trail.Value = Profile.Data.Items[Trail.Name]
			Trail:SetAttribute("Equipped", Profile.Data.Items[Trail.Name.."Equipped"])
		end
	end

	for _, Effect in ipairs(Effects:GetChildren()) do
		if Effect:IsA("IntValue") then
			Effect.Value = Profile.Data.Items[Effect.Name]
			Effect:SetAttribute("Equipped", Profile.Data.Items[Effect.Name.."Equipped"])
		end
	end
	
	--Update Values------------------------------------------------------------
	
	--Leaderstats--
	
	Leaderstats.Coins.Changed:Connect(function(CurrentValue)
		Profile.Data.Leaderstats.Coins = CurrentValue
	end)

	Leaderstats.Gems.Changed:Connect(function(CurrentValue)
		Profile.Data.Leaderstats.Gems = CurrentValue
	end)

	Leaderstats.Level.Changed:Connect(function(CurrentValue)
		Profile.Data.Leaderstats.Level = CurrentValue
	end)

	Leaderstats.Exp.Changed:Connect(function(CurrentValue)
		Profile.Data.Leaderstats.Exp = CurrentValue
	end)

	--Quests--

	Player.QuestNum.Changed:Connect(function(CurrentValue)
		Profile.Data.Quests.QuestNum = CurrentValue
	end)

	QuestStats.MetPete.Changed:Connect(function(CurrentValue)
		Profile.Data.Quests.MetPete = CurrentValue
	end)

	QuestStats.SticksCollected.Changed:Connect(function(CurrentValue)
		Profile.Data.Quests.SticksCollected = CurrentValue
	end)

	QuestStats.BoughtWire.Changed:Connect(function(CurrentValue)
		Profile.Data.Quests.BoughtWire = CurrentValue
	end)

	--Misc--

	Codes.Code1.Changed:Connect(function(CurrentValue)
		Profile.Data.Misc.Code1 = CurrentValue
	end)

	Codes.Code2.Changed:Connect(function(CurrentValue)
		Profile.Data.Misc.Code2 = CurrentValue
	end)

	Codes.Code3.Changed:Connect(function(CurrentValue)
		Profile.Data.Misc.Code3 = CurrentValue
	end)

	Player.Stats.TimePlayed.Changed:Connect(function(CurrentValue)
		Profile.Data.Misc.TimePlayed = CurrentValue
	end)

	Player.Stats.DateJoined.Changed:Connect(function(CurrentValue)
		Profile.Data.Misc.DateJoined = CurrentValue
	end)

	Player.VIPRewardTimer.Changed:Connect(function(CurrentValue)
		Profile.Data.Misc.VIPRewardTimer = CurrentValue
	end)
	
	--Settings--
	
	Settings.SFX.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.SFX = CurrentValue
	end)
	Settings.Music.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.Music = CurrentValue
	end)
	Settings.World.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.World = CurrentValue
	end)
	Settings.GraphicsQuality.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.GraphicsQuality = CurrentValue
	end)
	Settings.RealisticLighting.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.RealisticLighting = CurrentValue
	end)
	Settings.DayNightCycle.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.DayNightCycle = CurrentValue
	end)
	Settings.Weather.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.Weather = CurrentValue
	end)
	Settings.ShowLevel.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.ShowLevel = CurrentValue
	end)
	Settings.ShowTime.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.ShowTime = CurrentValue
	end)
	Settings.LevelDisplay.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.LevelDisplay = CurrentValue
	end)
	Settings.TimeFormat.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.TimeFormat = CurrentValue
	end)
	Settings.Notifications.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.Notifications = CurrentValue
	end)
	Settings.NotificationSounds.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.NotificationSounds = CurrentValue
	end)
	Settings.ShowOtherCosmetics.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.ShowOtherCosmetics = CurrentValue
	end)
	Settings.GuidingArrows.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.GuidingArrows = CurrentValue
	end)
	Settings.DialogueSpeed.Changed:Connect(function(CurrentValue)
		Profile.Data.Settings.DialogueSpeed = CurrentValue
	end)
end

local function PlayerAdded(Player)
	local Profile = ProfileStore:LoadProfileAsync(tostring(Player.UserId))
	if Profile ~= nil then
		Profile:AddUserId(Player.UserId) -- GDPR compliance
		Profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
		Profile:ListenToRelease(function()
			Profiles[Player] = nil
			-- The Profile could've been loaded on another Roblox server:
			Player:Kick()
		end)
		
		if Player:IsDescendantOf(Players) == true then
			Profiles[Player] = Profile
			-- A Profile has been successfully loaded:
			DoSomethingWithALoadedProfile(Player, Profile)
		else
			-- Player left before the Profile loaded:
			Profile:Release()
		end
	else
		-- The Profile couldn't be loaded possibly due to other
		--   Roblox servers trying to load this Profile at the same time:
		Player:Kick() 
	end
end

----- Initialize -----

-- In case Players have joined the server earlier than this script ran:
for _, Player in ipairs(Players:GetPlayers()) do
	task.spawn(PlayerAdded, Player)
end

----- Connections -----

Players.PlayerAdded:Connect(PlayerAdded)

Players.PlayerRemoving:Connect(function(Player)
	local Profile = Profiles[Player]
	if Profile ~= nil then
		Profile:Release()
	end
end)
3 Likes

Which line does it say in the output?