CAAplayer
(Chloe)
September 3, 2022, 6:27am
#1
How do I make this print:
[2] = ▼ {
[NeonBatDragon] = 1,
[NeonBatDragon] = 2,
[BatDragon] = 3
}
Instead of this:
[1] = "NeonBatDragon",
[2] = "NeonBatDragon",
[3] = "BatDragon"
}
Script:
local DataObject = {player.leaderstats.Cash.Value, {}}
for _,Pet in pairs(player.Pets:GetChildren()) do
table.insert(DataObject[2], Pet.Name)
end
print(DataObject)
1 Like
Mystxry12
(Mystxry)
September 3, 2022, 6:35am
#2
for index: number, Pet: Instance in pairs(player.Pets:GetChildren()) do
DataObject[2][Pet.Name] = index
end
2 Likes
CAAplayer
(Chloe)
September 3, 2022, 6:46am
#3
ty but it only prints:
[2] = ▼ {
["NeonBatDragon"] = 3
I want it to print all the pets, not just the last one
1 Like
CAAplayer
(Chloe)
September 3, 2022, 6:49am
#5
I tried that already. How do I make it print all the pets?
1 Like
Mystxry12
(Mystxry)
September 3, 2022, 6:50am
#6
You have duplicate pets with the same name, so it overwrites their data, and FYI you can’t have the same keys in a dictionary.
1 Like
CAAplayer
(Chloe)
September 3, 2022, 6:54am
#7
Is there a way to fix that? or the only way to fix it is to change the name of the pets
1 Like
Mystxry12
(Mystxry)
September 3, 2022, 6:56am
#8
Yes, you have to change the pet names or you have to use arrays. If you really want duplicate pets you have to use arrays.
1 Like
CAAplayer
(Chloe)
September 3, 2022, 6:57am
#9
How do I fix it using arrays? I am not familiar with arrays
1 Like
Mystxry12
(Mystxry)
September 3, 2022, 6:59am
#10
for index: number, Pet:Instance in pairs(player.Pets:GetChildren()) do
table.insert(DataObject[2], {Name = Pet.Name, Index = index})
end
Then just,
print(DataObject[2]) -- {{Name = ..., Index = 1}, {Name = ..., Index = 2}, ...}
Does this work @CAAplayer
3 Likes