local Table = {"Cat", "Dog"}
local function UpdateEquip()
for _, Pets in pairs(Pet:GetChildren()) do
Pets:GetPropertyChangedSignal("Value"):Connect(function()
if Pets.Value == true then
print(Pets)
table.insert(Table, Player:FindFirstChild(Pets.Name))
elseif Pets.Value == false then
print(Pets)
table.remove(Table, Player:FindFirstChild(Pets.Name))
end
end)
end
end
Every variable works as intended but as the title states that I cannot insert a Pet to the table when property is changed. Any ideas?
Weird… It only prints out Cat even when the property value changed for both the Cat and Dog. There is something wwrong about my code probably unrelated to the post
local EquippedDataStore = DataStoreModule("Equipped", Player)
local function UpdateEquip(Value)
Table = EquippedDataStore:Get(Value)
for _, Pets in pairs(Pet:GetChildren()) do
UpdateEquip(Table)
EquippedDataStore:OnUpdate(UpdateEquip)
Well, I asked for the data saving code, but one problem would be
You send over the table, but try to get the data of the table…?
local function UpdateEquip(Table)
for _, Pets in pairs(Pet:GetChildren()) do
Pets:GetPropertyChangedSignal("Value"):Connect(function()
if Pets.Value == true then
print(Pets)
table.insert(Table, Player:FindFirstChild(Pets.Name))
elseif Pets.Value == false then
print(Pets)
table.remove(Table, Player:FindFirstChild(Pets.Name))
end
end)
end
end
UpdateEquip(Table)
EquippedDataStore:OnUpdate(UpdateEquip)
I’m not sure how OnUpdate works with ds2 (I don’t use ds2), but I believe it will pass the table as well.
That is how data saving works in Datastore2 I believe. I think what I did was getting the default value of the table and adding onto the table when value changes. I’m not saving the table yet because it errors.
Can you tell me what you mean by this
You send over the table, but try to get the data of the table?
local function UpdateEquip(Table)
for _, Pets in pairs(Pet:GetChildren()) do
Pets:GetPropertyChangedSignal("Value"):Connect(function()
if Pets.Value == true then
print(Pets)
table.insert(Table, Player:FindFirstChild(Pets.Name))
elseif Pets.Value == false then
print(Pets)
table.remove(Table, Player:FindFirstChild(Pets.Name))
end
end)
end
end
local function UpdatedEquipped(Value)
UpdateEquip(EquippedDataStore:Get(Value))
end
UpdateEquip(Table)
EquippedDataStore:OnUpdate(UpdatedEquipped)
I also don’t work with ds2 much, but the main problem was that you were trying to get a saved value from the original table. Another problem might be overlapping connections.