Getchildren on Prompt GamePass Purchase Finished doesn't seem to work?

I’m currently trying to make it so it getchildren all gamepass values to onPromptGamePassPurchaseFinished. Automatically gives them the product upon purchases, but that doesn’t seem to work.

local Players = game:GetService("Players")
for i,v in pairs(game.ReplicatedStorage:GetDescendants()) do
	if v.Name=="Gamepass" then
		local gamePassID = v.Value
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)

	if purchaseSuccess == true and purchasedPassID == gamePassID then
		print(player.Name .. " purchased the game pass with ID " .. v.Value)
		local str ="NumberValue", player.Character.Gamepass)
		end end

I’m doing this because I have a bunch of values. So It’d be smarter to do a getchildren. Anything helps, thank you in advance.

Hi, I’ve rewritten your code to fix the issues that I saw.

local function PGPPFinished(Player, PassID, Success)
	if Success then
		local NewValue ="NumberValue")
		NewValue.Name = tostring(PassID)
		NewValue.Value = PassID
		NewValue.Parent = Player.Character:WaitForChild("Gamepass", 1)


I’m not sure what the use of ReplicatedStorage was in your script, nor am I sure why you’re storing the player’s gamepasses in their character instead of their PlayerObject. If you could provide some more context, I could certainly provide more feedback on this code.

Yeah, already solved it a while ago. Thanks though