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

How can I reference all items in a table and change them all at the same time?

Referencing Entire Table?

Hey guys, so I am trying to work on a project where a large number of gui items are being put into a table to make working with them easier. Only issue currently is I am trying to write a function to make all of them fade, but no matter how I do it it only does them one by one instead of the entire table at once. How would you work around this? I'm not really well versed in coroutines as I figure it will involve that somehow.

This is how the table is set up:


local FloorImages = script.Parent:GetChildren()
local Floor = script.Parent.Parent.Parent
local Labels = {} 

for i=1,#FloorImages do
	if FloorImages[i].Name == "Tile" then
		table.insert(Labels, FloorImages[i])
	end
end

--Here is what was being used to try and fade them all at once

function fadefull()
	for i, v in pairs (Labels) do
			for i = 0, 1, 0.1 do
				v.BackgroundTransparency = i
				wait(.2)
			end
		end
	wait()
end

5 comments

0

I'm not sure what part of this would make them "fade" and it's not possible to do more than one thing at t time, just make sure they're done in the right order. You'll simply have to iterate the table as you've already done. Just make sure there's no yielding between each element.

0

I didn't include the actual part as all of them were broken, how can I have them all fade at once without yielding at all? The way I was fading them was using a for i = 0, 1, 0.1 do and then changing the transparency to i but without a yield its instant when I want it to fade smoothly.

0

Can you include the code you are using to fade the gui parts.

0

Added to post

0

Use Tween for smooth non-yielding transitions

1 answer

✓ Accepted answer

Using TweenService you can smoothly transition values without yielding. You still have to do them "one at a time" code wise, the animations will still play at the same time.

local FloorImages = script.Parent:GetChildren()
local Floor = script.Parent.Parent.Parent
localLabels = {}

for i=1,#FloorImages do
		if FloorImages[i].Name == "Tile" then
		table.insert(Labels, FloorImages[i])
	end
end

local TS = game:GetService("TweenService")
local tween_info = TweenInfo.new(2) -- feel free to changes style etc with further parameters
local tween_goal = {BackgroundTransparency = 1}

function fadefull()
	for i, v in pairs(Labels) do
		local tween = TS:Create(v, tween_info, tween_goal)
		tween:Play()
	end
end

4 comments

0

pls use local functions XD

0

You're actually a lifesaver, and I wasn't aware of that so thanks for the information my man!

0

Yeah you could add local variables, I just copied/pasted his code. Not the biggest of deals.

0

promoting good practice :3

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