Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you get all the buttons and make them do something ?

This supposed to enable a "Glow" imagelabel in a button that it's either CLICKED, HOVERED or LEFT THE MOUSE from it, how do i script it correctly, because i haven't been scripting for 2-3 months and i need to remember some stuff, can someone give me a hand ? Thanks :)

local buttons = script.Parent:WaitForChild("Apps")

for i,v in pairs(buttons:GetChildren()) do 
  if v.ClassName=="ImageButton" then
     v.Button1Down:connect()	
	end
end

local function enableGlow(btn)
  	--
  	
end

local function disableGlow(btn, listOfButtons)

end

local buttonList = script.Parent:WaitForChild("")

for _,button in pairs(buttons:GetChildren()) do 
		if button.ClassName=="ImageButton" then
    		button.MouseEnter:Connect(function() enableGlow(button) end)
    		button.MouseLeave:Connect(function() disableGlow(button, buttonList) end)
    		button.MouseButton1Click:Connect()
  	end
end

1 answer

✓ Accepted answer

For this you will need a list of the buttons to connect the events too:-

local function enableGlow(btn)
    print('Enable glow on:-',btn) -- this will print the button name
end

local function disableGlow(btn, listOfButtons)
	print('disable glow on:-', btn)
	-- we could also use the list of buttons to disable the glow as all buttons should have the glow off
-- this should stop some gliches with events which can be seen in some games e.g. when multiple buttons look like they have a mouse over
end

local buttonList = script.Parent:WaitForChild("Apps"):GetChildren() -- returns an array of parts

for _,button in pairs(buttonList ) do  -- using the array of parts we only connect events to the Image buttons
        if button.ClassName=="ImageButton" then
            button.MouseEnter:Connect(function() enableGlow(button) end)
            button.MouseLeave:Connect(function() disableGlow(button, buttonList) end)
            button.MouseButton1Click:Connect() -- as each button will do different thing, this may or may not be possible
-- you might need to connect the click event individually 
    end
end

I hope this helps.

This discussion is preserved as it was. New answers, comments, and votes are closed.