How can I make a function activate himself, here’s a bit more explenation about my problem. Let’s say I have a for loop wich needs to be activated when something is bought, but in the for loop we do mousebutton1up and then you but it so the bought function need to reactivate himself so the for loop will check all the new items. Here’s an example:
function loop()
for i,v in pairs(something)
item.mousebutton1up:connect(function()
-- buy item
-- and here inseard new item but then we need to reactivate the function
loop()
end
end)
Yes, this would be possible, but I would add the connections into a table and disconnect them when running the function. ex:
local connections = {}
function loop()
for i,v in pairs(connections) do
v:Disconnect()
end
for i,v in pairs(something) do
local conn
conn = v.MouseButton1Up:Connect(function()
loop()
end)
table.insert(connections, conn)
end
end
This is just to prevent overlapping functions, which would cause errors/duplications in code