Multiple Button Activated

I have created a module to make buttons easier, but I wanna make that just 1 button is activated at the time. When I select one and select another one, it will deselect everything, this is a problem because I don’t wanna deselect the latest one selected.

local function buttonActivatedDetection(buttonID: number)
	if MultipleButtonActivated == false then
		for i, v in pairs(xyonGui.ButtonsContainer:GetChildren()) do
			if v:IsA('Frame') then
				if v.Local:GetAttribute('state') == true then
					if v.Name ~= tostring(buttonID) then
						v.Local:SetAttribute('state', false)
					end
				end
			end
		end
	end
end
1 Like

2 Likes

I assume with this you automatically set every other button to false
Since it doesn’t match buttonID

If I haven’t messed this up my code below, it should work as a toggle and interact only with the matching case:
v.Name == tostring(buttonID)

You also may not need if v.Local:GetAttribute('state') == true then due to our toggle behavior which will change the state.

Code to toggle

local function buttonActivatedDetection(buttonID: number)
	if MultipleButtonActivated == false then
		for i, v in pairs(xyonGui.ButtonsContainer:GetChildren()) do
			if v:IsA('Frame') then
				if v.Name == tostring(buttonID) then
					local currentState = v.Local:GetAttribute('state')
					v.Local:SetAttribute('state', not currentState)
				end
			end
		end
	end
end

Additionally I think MultipleButtonActivated should be checked as true:
if MultipleButtonActivated == true then

2 Likes

I’ve got it worked using local and not the module. Thanks to help me, I wont have the same error again.

1 Like