Working on a sim and struggling to get this local function to work within this script, keeps outputting as nil anyone got any feedback thank you in advance
sorry cant get this script to indent, kinda new here, there more lines of code in this script but this is the part that isn’t working
local function Multiplier(plr, Multiplier1)
local Multi = 0
for i,v in pairs(plr.Pets:GetChildren()) do
if v.Equipped.Value == true then
Multi = Multi + v[Multiplier1].Value
end
end
return Multi
end
local function Multiplier(plr, Multiplier1)
local Multi = 0 -- Multi is Zero
for i,v in pairs(plr.Pets:GetChildren()) do -- indexing a table
if v.Equipped.Value == true then
Multi = Multi + v[Multiplier1].Value -- 0 + ???
end
end
return Multi -- ???
end
Ok so, looking at your Code, you frogot to add the Arguments inside the function:
local multiplier = Multiplier() -- where are the Arguments???
local function Multiplier(plr, Multiplier1) -- two arguments???
local Multi = 0
for i,v in pairs(plr.Pets:GetChildren()) do
if v.Equipped.Value == true then
Multi = Multi + v[Multiplier1].Value
end
end
return Multi
end
Use the variable multiplier itself, you might want to change the multiplier variable name in the event scope and multiplier variable name in the global scope.
Totally makes sense, so its getting the children in Pets which would be Pet1, Pet2 etc, would you know how to look for the Multiplier1 in each of the Pets instead to retrieve those values to add in order to get a total multiplier? Sorry may not may sense, I do appreciate the help thank you
You can either use :GetDescendants() or two for loops (not recommended). GetDescendants might not be what you’re looking for.
for _, folder in player:GetChildren() do
for _, value in folder:GetChildren() do
if value:IsA("StringValue") then
print(value.Value)
end
end
end
-- or use GetDescendants() to get all descendants of a folder
for _, value in player:GetDescendants() do
if value:IsA("StringValue") and value.Parent.Name == "FolderName" then
print(value.Value)
end
end
Believe it or not I finally managed to get it to work, the argument was one of the main factors but after that the error still showed but worked completely fine lol thanks for the help!