Help debugging / fixing script

Explained quickly and simple :
System where when you have a pet or Multiple Pets equipped you get a multiplier from each pet and combine those multipliers to add more points / currency to the player when player does something where he gets Currency.
NÀyttökuva 2022-04-15 012325

That is the folder where the Pets are kept inside The Player.

Script inside ClickDetector that gives Money when clicked ( for example )

local ClickDetector = script.parent
function onMouseClick(Player)
-- Here should be the rest of the script , but it has nothing to do with this topic.
-------------------------
	function getMultiplier(Player, Multiplier1)
			
			local Multi = 1
			for i,v in pairs(Player.Pets:GetChildren()) do
				if v.Equipped.Value == true then
					Multi = Multi + v[Multiplier1].Value
					
			
					
					
				end
			end
			return Multi
end
local Multiplier1 = getMultiplier()
local pointsamount = game.ServerStorage.Points.Value * Multiplier1()--trying to get the Multi from the function.--
Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + pointsamount




clickDetector.MouseClick:connect(onMouseClick, getMultiplier)

So, what is the problem?
well, I believe I made a mistake somewhere where It does not correctly get the GetMultiplier value/number and instead says that "Attempt to index nil with pets on line “for i,v in pairs(Player.Pets:GetChildren()) do”.
I need help learning this because I can’t find solutions and I tried posting about a similar problem earlier and keep getting close to no responses, so would really be appricated.
Also Keep In Mind ( I am new so I don’t get what I do wrong usually while wirting scripts.)

1 Like

I think It’s because you are not passing any player reference in your getMultiplier() function.

local Multiplier1 = getMultiplier()

Didn’t pass anything to the function. It needs a player object I think.

Like you need to do something like

local Multiplier1 = getMultiplier(Player)

and then you can move the getMultiplier function outside of the onMouseClick function:

function getMultiplier(Player, Multiplier1)
	local Multi = 1
	for i,v in pairs(Player.Pets:GetChildren()) do
		if v.Equipped.Value == true then
			Multi = Multi + v[Multiplier1].Value
		end
	end
	return Multi
end
function onMouseClick(Player)
	-- Here should be the rest of the script , but it has nothing to do with this topic.
	-------------------------
	local Multiplier1 = getMultiplier(Player, "something idk")
	local pointsamount = game.ServerStorage.Points.Value * Multiplier1
	Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + pointsamount
end

clickDetector.MouseClick:Connect(onMouseClick) -- also you should only pass one function to :Connect

“Something Idk” ?
(Player, "something idk")
What should I put there Because I believe I need to put something there that I should know , But I kinda don’t

So v is an object inside of Player.Pets (which im guessing is a ‘Pet’)
and Multiplier1 is the second argument in getMutliplier. I don’t know what’s inside of a ‘Pet’ object. It looks like “something idk” is the name of a NumberValue object inside of a ‘Pet’. I think it’s a NumberValue or IntValue because your summing up all the values of Multiplier1 name and returning that sum.