Hi, I have been creating a pet system and it has been working fine, but when the player starts to gain a lot of pets, this error occurs -
Players.cookie0609life.PlayerGui.Main.PetInventory.MainFrame.EquippedDisplay.TextLabel.LocalScript:11: attempt to index nil with 'Equipped'
It stops the inventory from working as intended, I cannot find a way to fix this issue, it would be great if someone could help me out.
Here is my script:
local l__LocalPlayer__1 = game.Players.LocalPlayer;
local l__Pets__1 = l__LocalPlayer__1:WaitForChild("Pets");
local u2 = 0;
function totalEquipped()
local v2 = l__Pets__1:GetChildren();
local v3 = #v2;
local v4 = 1 - 1;
while true do
if v2[v4].Equipped.Value == true then
u2 = u2 + 1;
end;
if 0 <= 1 then
if v4 < v3 then
else
break;
end;
elseif v3 < v4 then
else
break;
end;
v4 = v4 + 1;
end;
return u2;
end;
while wait(1) do
totalEquipped();
script.Parent.Text = u2 .. "/" .. l__LocalPlayer__1:WaitForChild("Data"):WaitForChild("MaxEquip").Value;
u2 = 0;
end;
I never knew what this was and i just did some research, but now i do know what it is. I never used this app or exploit. It was from a free model that i got.
If it’s from a free model don’t worry about it especially if you’re new to programming and didn’t know! This would be the uploaders fault and not yours. There’s no way to prevent people from using SynX to steal games currently and I highly doubt that there will be one in the future. Anyways, the code here doesn’t make very much sense. :GetChildren() returns a table of all instances parented to the instance you use it on.
At these lines:
local v2 = l__Pets__1:GetChildren();
local v3 = #v2;
local v4 = 1 - 1;
if v2[v4].Equipped.Value == true then
We know that 1 - 1 = 0, so v4 = 0. In the :GetChildren() table that we talked about above, there is no 0 index. It starts at 1 and goes up, so at the conditional statement line, v2[v4] would be nil, therefore giving you the error.
From reading through it, this script seems to be pretty broken, and I would recommend that you find a new one or ask for help writing your own on this forum after making an attempt to do so. I listed some resources below that could come in helpful (or not), depending on what it is you’re trying to make.