So, I started writing code for my UI since yesterday and I’ve been stuck with this one really annoying issue that I somehow cannot seem to locate myself ( Could be cause of my mental disabilities that make me unable to comprehend the issue, which is why I am asking for help with this. ).
The issue is rather simple, but I for the love of god cannot figure out what causes it,
long story short, I have a list of frames that upon clicking fire a remote to equip a pet, code:
for k, v in pairs(team.PetList:GetChildren()) do
if v:IsA("Frame") then
v.ImageButton.MouseButton1Click:Connect(function()
if petSelected == '' then
handlers.FunctionHandler:InvokeServer('EquipPet', v.petName.Value, 0, false)
else
handlers.FunctionHandler:InvokeServer('EquipPet', petSelected, v.Name, true)
end
end)
end
end
and the function for the remote:
Bindables.EquipPet.Event:Connect(function(player, petName, spot, equip)
local data = userDatas[player.userId].pets
if equip then
for _, v in pairs(data) do
if v.equipped and v.slot == spot then
v.slot = true
v.equipped = false
end
end
data[petName].equipped = true
data[petName].slot = spot
else
data[petName].equipped = false
data[petName].slot = false
end
end)
The issue is, whenever I press one of the buttons inside the list, it equips ALL of the pets into the same slot no matter what I do, I tried to spam the buttons and after a while the code managed to work as intended (???) - I only managed to replicate the fix 3 times, it seems to be very random.
I made it print the variables and they seem fine, but for some odd reason the code just affects every single pet I have in the inventory instead of the specifically selected one despite specific statements in the code.
(Pets:171 - prints selectedPet and petSlot)
(DataHandler:227 - prints player, selectedPet, petSlot and equip)
(DataHandler:228 - prints pet data before edits)
(DataHandler:249 - prints pet data after edits)
I edited the rest of the code that’s in any sort of way connected to this one, and it isn’t what’s causing the issue which is why I specifically show only these scraps, I personally feel like it could be something with the EquipPet.
I’d appreciate any sort of help or navigation with what could possibly be the issue, so far I’ve only managed to narrow it to those two pieces of code, I don’t know what could be the issue with them though.