So I made a gui with 'check boxes' and when you click one 'box' it should change the corisponding values to true or false, I'll include a model so you can see it for yourself. I don't get any errors, it just won't work. https://www.roblox.com/Thanks-ScriptingHelpers-item?id=456562045 ^^ Model thanks
local faces = script.Parent.Face local FacesTable = { Back = false, Bottom = false, Front = false, Left = false, Right = false, } for index, child in pairs(faces:GetChildren()) do child.Display.MouseButton1Click:connect(function() CheckVars() local var = nil local vartab for i, v in pairs (FacesTable) do if i == child.Name then print(i .. " = " .. tostring(v)) print("Value found!") var = v vartab = i if v == false then print("var was false") v = true print(vartab .. " = " .. tostring(v)) child.Display.Style = 1 return elseif v == true then print("var was true") v = false print(vartab .. " = " .. tostring(v)) return end end child.Display.Style = 2 return end end) end function CheckVars() for i, v in pairs (FacesTable) do print(tostring(i) .. " = " .. tostring(v)) end end
Okay, there are two major errors with your script that I can find. I'll go through them.
Return statement in the for pairs loop
On line 34, you are ending the event handler (that you created on line 10) after the first iteration of the for pairs loop (where you're trying to loop through the FacesTable). If the first child is not the one your clicked on, it will not do anything, since the loop has ended.
I'm not sure why that is there at all, so I just removed it.
Checking a dictionary
This is not actually an error, but if you looking for a specific index in a dictionary (a table with string keys, like 'FacesTable'), there's no need to loop through the table.
if FacesTable[child.Name] then -- Checks if the 'child.Name' index of FacesTable has a value. -- code end FacesTable[child.Name] = true -- Sets the 'child.Name' index of FacesTable to 'true'.
Setting table values
This is the other major error.
When looping through a table with the pairs function, you do not set a new value by changing 'v'. 'v' is local to the loop only, and does not index the table (it is only the key value). If you want to change a table value, you have to index it with something like FacesTable[i] = true
.