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.
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.)
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.