I am working on a GUI that allows a player to select a character. When a character is selected before they are spawned a value is sent to an intValue within the GUI to track which character is currently selected. How would I go about comparing that intValue to the table provided below? Since intValue changes when ever the player clicks the character as a currently selected to bring up profile information, I'm assuming it would need a .changed:Connect
local t = { [1] = function() return game.ReplicatedStorage.C1 end, [2] = function() return game.ReplicatedStorage.C2 end, [3] = function() return game.ReplicatedStorage.C3 end, [4] = function() return game.ReplicatedStorage.C4 end }
To check for something in a table, you need to search for it's key, for example:
local table = { [1] = true, ["entry"] = true } print(table[1],table["entry"]) -- would print "true true"
So, your code would be:
local t = { -- entries here } local val = GUI.IntValue val.Changed:connect(function() t[val.Value]() -- calls the function end)
Hope I helped!
~TDP