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

How to perform a function to multiple objects?

I am trying to tween the color of all ImageLabels that is a descendant of Frame. I would do GetAllChildren() however, there are other objects besides Image Labels in the Frame.

How would I reference ALL image labels in the Frame as one variable? That way I can easily perform actions to them.

local Button = script.Parent:WaitForChild("Button")
local Frame = script.Parent


function debounce(func)
    local isRunning = false    -- Create a local debounce variable
    return function(...)       -- Return a new function
        if not isRunning then
            isRunning = true
 
            func(...)          -- Call it with the original arguments
 
            isRunning = false
        end
    end
end

function isImage( Image )
    return Image:IsA("ImageLabel") and Image:IsAncestorOf(Frame)
end



Button.MouseButton1Down:connect(debounce(function(func)

print('Button pressed!')


local color3 = Color3.new
local vec3 = Vector3.new

local vec3toColor3 = function(vec)
	local newvec = vec3(vec.x/255, vec.y/255, vec.z/255)
	return color3(newvec.x/255, newvec.y/255, newvec.z/255)
end

function color3toVec3(col)
 return vec3(col.r*255, col.g*255, col.b*255)
end

function tween_color(start_color,end_color,alpha)
local start = start_color
local endme = end_color
local startvec = color3toVec3(start)
local endvec = color3toVec3(endme)
return vec3toColor3(startvec:lerp(endvec,alpha))
end
while true do
	for i = 0,1,.1 do
	Image.ImageColor3 = tween_color(color3(81, 183, 255),color3(36, 79, 113),i)
	wait(.1)
	end
	for i = 1,0,-.1 do
	Image.ImageColor3 = tween_color(color3(81, 183, 255),color3(36, 79, 113),i)
	wait(.1)
	end		
end
end))

1 answer

✓ Accepted answer

Use for i,v in pairs() do;

http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#pairs

Either put all of the parts you want in a table and use this loop on them or have all of the parts under one parent and use :GetChildren(). This loop checks all the posibilities and does what you want them to do.

like;

for index,variable in pairs(Workspace:GetChildren()) do
if variable:IsA("Part") then
variable.Name = "LoppyMoney"
end
end

Hope this helps :)

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