Ciao,
I have a function that should return the i of the for.
Well, it doesn’t. The cycle ends as it should when the user clicks a button, but the return is always nil.
function Vediamo(Opzioni)
local Clicked = false
while Clicked == false do
for i = 1,#Opzioni do
Opzioni[i].MouseButton1Click:Connect(function()
Opzioni[i].Parent.Visible = false
Clicked = true
return i
end)
end
wait(0.1)
end
end
local Opzioni = {
Convo.Opzioni.la1,Convo.Opzioni.la2,Convo.Opzioni.la3
}
local Scelta = Vediamo(Opzioni)
print(Scelta) -- print == nil
If you see, the Vediamo function doesnt return anyting at all, the code
This Line of code is inside the function that is connected to MoueButton1Click Event, so that function will return i, not the Vediamo Function,
and since the function returning i is connected to an event, so no one is using that return. if you want to print every time The Opzioni buttons are getting clicked, you may replace that return i with print(i)
Vediamo function is just connecting events to it, make sure u also call Vediamo function.
--Variabili
local Opzioni = {}
local function Vediamo(Opzioni)
local Clicked = false
while Clicked == false do
for i = 1,#Opzioni do
Opzioni[i].MouseButton1Click:Connect(function()
Opzioni[i].Parent.Visible = false
Clicked = i
return i
end)
end
wait(0.1)
end
end
--Funzione
Cartello.MouseClick:Connect(function(Giocatore)
Opzioni = {
Convo.Opzioni.la1,Convo.Opzioni.la2,Convo.Opzioni.la3
}
local Scelta = Vediamo(Opzioni)
print(Scelta)
end)
function Vediamo(Opzioni)
local Clicked = false
repeat
for i,v in pairs(Opzioni) do
v.MouseButton1Click:Connect(function()
v.Parent.Visible = false
Clicked = true
return i
end)
end
wait(0.1)
until Clicked
end
local Opzioni = {
Convo.Opzioni.la1,Convo.Opzioni.la2,Convo.Opzioni.la3
}
local Scelta = Vediamo(Opzioni)
print(Scelta) -- print == nil
A few fixes maybe try now? (I kind of just cleaned the code a bit)
Well you do seem to be declaring the options correctly but there is no options in the table. Also I think another issue is that the for loop doesn’t know how much to count by because you are only giving 2 numbers instead of 3.