#Why does this function not respond to return?

1 messages · Page 1 of 1 (latest)

upper bobcat
#

Here is my function inside a module, then i call the function however the childadded doesnt listen to the return unless i write it without the function. Here is my code if you dont understand.

#
--Function
function DetectChange(Child, ImageLabel, SpecificTag, Icon)
    local Tags = Child:GetTags()
    if table.find(Tags, SpecificTag) then
        ChangeImage(ImageLabel, Icon, true)
        print("Changed icon to ".. SpecificTag.."Icon")
        return
    end
end
#
function HotbarModule.Added()
    for _, v in HotbarModule.uiElements do
        local Image = v:FindFirstChildOfClass("ImageLabel")
        
        local Bool = v:FindFirstChildOfClass("BoolValue")
        Bool.ChildAdded:Connect(function(Child)
            --If Statements
            if not Child:IsA("Tool") then print("Child isn't a tool") return end
            
            local IconTable = ItemProperties.Icons
            DetectChange(Child, Image, "Sword", IconTable.SwordIcon)
            DetectChange(Child, Image, "Pizza", IconTable.PizzaIcon)
            DetectChange(Child, Image, "Burger", IconTable.BurgerIcon)
            --DetectChange(Child, Image, "Part", IconTable.PartIcon)
            local Tags = Child:GetTags()
            if table.find(Tags, "Part") then
                ChangeImage(Image, IconTable.PartIcon, true)
                print("Changed icon to ".. "Part")
                return
            end
            --If the tool is none of the above, set it to this one under.
            ChangeImage(Image, IconTable.PlaceholderIcon, true)
            warn("Did not find tag, have you forgotten to set a tag for this part? Report to developer.")
            return
        end)
    end
end
#

as you see I discarded the local function to try and test it out raw, and I came to the conclusion that the function does not listen to the return unless it isnt inside a function

#

also is my code good smile

shy dagger
#

I guess this is the local function correct

local function BoolChildAdded(Child)
            --If Statements
            if not Child:IsA("Tool") then print("Child isn't a tool") return end
            
            local IconTable = ItemProperties.Icons
            DetectChange(Child, Image, "Sword", IconTable.SwordIcon)
            DetectChange(Child, Image, "Pizza", IconTable.PizzaIcon)
            DetectChange(Child, Image, "Burger", IconTable.BurgerIcon)
            --DetectChange(Child, Image, "Part", IconTable.PartIcon)
            local Tags = Child:GetTags()
            if table.find(Tags, "Part") then
                ChangeImage(Image, IconTable.PartIcon, true)
                print("Changed icon to ".. "Part")
                return
            end
            --If the tool is none of the above, set it to this one under.
            ChangeImage(Image, IconTable.PlaceholderIcon, true)
            warn("Did not find tag, have you forgotten to set a tag for this part? Report to developer.")
     return
 end```
#

if so the change image function probably wouldn't run and would error in the first place, and would never reach the return line at the bottom

shy dagger
upper bobcat
#

no the detectchange is actually the local function, that one i use it in a local script

solemn lodge
#

im not sure what your issue is exactly however

upper bobcat
#

alright thank you! thanks to a_machines help i changed table.find to

local imagelogic = {
    ChangeImaging = function(Image, IconID, Tag)
        ChangeImage(Image, IconID, true)
        print("Changed icon to ".. IconID, Tag)
    end,
}
for i, Tag in Tags do --Check the tags a name, then use the same name to set the icon to its used icon
                if IconTable[Tag.."Icon"] then imagelogic.ChangeImaging(Image, IconTable[Tag.."Icon"], Tag) return end
            end

My original issue was that childadded didnt listen to return, but thats all fixed now

solemn lodge
#

oh

#

nice

upper bobcat
#

In one of my module scripts, i had a sorting function that essentially sorts the items to the first button, if that button is full then go to the next so on. I realised i needed to do the same for inventory if the player had max items, well i successfully did that. However i ended up making a seperate module called sortingmodule where i took the sorting from that first module, duplicated the function and made one for inventory and one for the hotbar. was that a good idea @shy dagger (dont mind the ping)

#

anything that resembles eachother slightly i shall put inside a seperate module with some parameters

tender owl