I’ve encountered quite possibly the most confusing bug today and I still haven’t managed to fix it. For some odd reason, selectingItem is being overwritten by another variable, despite not even being called in the getChestInfo function??
Here, take a look.
function getchestinfo(slot, info)
if chestInspecting and UIup == true and gui.chest.Visible == true then
local folder = chestInspecting.chest.StoredItems
if folder:FindFirstChild("slot"..slot) then
local slotFound = folder:FindFirstChild("slot"..slot)
local returningData = slotFound
if info == true and slotFound.ItemName then
local SaveThisData = {}
SaveThisData = itemmodule.ReturnInfo(slotFound.ItemName.Value)
SaveThisData.slot = slot
if selectingItem then
--prints the selectingItem health (currently unmodified)
print(selectingItem.health)
end
if slotFound:FindFirstChild("Health") then
SaveThisData.health = slotFound.Health.Value
end
if selectingItem then
--prints the selectingItem health, but it gets modified despite it only changing the SaveThisData variable???
print(selectingItem.health)
end
if slotFound:FindFirstChild("StackNumber") then
SaveThisData.amount = slotFound.StackNumber.Value
end
returningData = SaveThisData
end
return returningData
end
end
end
Noticed a issue? Probaly not. Nothing else in the script is modifying the selectingItem variable, but it still does it anyway.
What data is selectingItem assigned before this function? If it’s not being modified anywhere else, it seems it must be connected to SaveThisData.health in some way.
It may also help if you show the output and add a print for the output of SaveThisData.health as well.
selectingItem is a variable that shows which item the player is holding while looking in a chest. It’s modified when the player drops the item or puts in a slot of the Chest. In this case, this bug happens when the player has a item selected, and clicks on another item (which will swap them), but if both items are the same, and one of them has lower health, it will just end up setting its health to the one that just swapped, causing this bug.
It seems to modify the health value specifically when the getChestInfo function is called. Despite it only being a function that returns the info of the item in the Chest.
The module called has this function:
function module.ReturnInfo(name)
if name:match(" BreakableBlock") then
name = string.gsub(name, " BreakableBlock", "")
end
local found = nil
for i,v in pairs(blocks) do
if v.name == name then
found = v
end
end
for i,v in pairs(melee) do
if v.name == name then
found = v
end
end
for i,v in pairs(food) do
if v.name == name then
found = v
end
end
if found then
return found
end
end
Turns out that just setting a variable to something from another table causes bugs, so i had to copy all the properties to a new table. And that fixed it, good golly. That took HOURS.