Problem with modulescript

Hello, I have a module script that has the Button name and the gamepass ID. This is the template:

local Mod = script.ModuleScript
local Buttons = script.Parent:GetDescendants()

for i,Button in pairs (Buttons) do
	if Button:IsA("ImageButton") then
			for BName,Id in pairs (Mod:GetDescendants()) do
				if Button.Name == BName then
					game:GetService("MarketplaceService"):PromptPurchase(game.Players.LocalPlayer, Id)

This is not sufficient information for us to help you, you haven’t even told us what’s the problem here or what the context of the script is?

Please edit your post to meet the Category’s topic template shown in it and also follow the rules:

1 Like

The first 2 lines are not correct since you don’t put the module in a variable. The Mod variable is just a reference to the ModuleScript, not the module itself. To fix it, you should replace the first two lines with:

local Mod = require(script.ModuleScript)

then adapt rest of the script to it.

Also next time, please provide the information about the problem, like @Nerkonl said.

1 Like

so what’s the problem exactly?

require is not being used here correctly, a value from a ModuleScript is returned by a call to require, store that in a variable to make use of the ModuleScript’s contents

require() works this way

local var = require(module)
1 Like

Problem is at line 8, which I want it to put “Bname” as the first thing in the module script and “Id” after the =

Fixed, I just needed to remove the :GetDescendants.
Thanks for everyone that helped me with the first line!