#Why does this function not respond to return?
1 messages · Page 1 of 1 (latest)
--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 
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
if this is a private function inside of a module then its better to do
local function name()
end
instead of
function name()
end
no the detectchange is actually the local function, that one i use it in a local script
decent. I see some stuff that could cause issues later down the line
im not sure what your issue is exactly however
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
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
The return isn't doing anything. If your statement is true, it returns nothing manually. If it's false, it returns nothing automatically.