Fade all coins in a folder

Should this script fade all coins?
It fades only one coin then stops.
No errors in the output folder.

while true do
wait()
if game.Players.LocalPlayer.Round.MaxCoins.Value == true then
local Coins = workspace.Coins:GetDescendants()

	for i, Coin in pairs(Coins) do
		
		Coins[i].Spin:Destroy()
		repeat
			Coins[i].Transparency = Coins[i].Transparency + 0.05
			wait(0.005)
		until Coins[i].Transparency == 1
		
	end
end

end

Thanks!

In the “until” line, where you put the == sign; does changing it to >= do anything?

Still fades only one coin.
Hmmmmmmm…

The script will yield until the first coin has faded, and then will start fading the second coin, and wait till that coin faded, and so on. This is because this is all being done in a single thread. You could make a for loop on top, and have it be something along the lines of for i = 0, 1, 0.05 do and loop through each coin and set it’s transparency to i. You could also create a new thread for each coin if you don’t wish to change the repeat loop.

Do you have an example I could go off of?

I think that the for loop fades only one coin at a time because of waiting for one coin to fade away. I suggest using TweenService.


local Coins = Folder:GetChildren()
local TS = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
-- put tween info inside here
)

local properties = {
  Transparency = 1
}

for i, Coin in pairs(Coins) do

  -- create a tween for each coin and play it
  
     local tween = TS:Create(Coin, tweenInfo, properties)
     tween:Play()

  -- use spawn or coroutine to destroy the coin without yielding the loop

  spawn(function()

     tween.Completed:Wait()
     Coin:Destroy()

  end)

end

Hopefully this helps.

1 Like

It seemed to work!! Is there a way I can speed up the fade? If so, let me know! Thanks!

Inside of TweenInfo, you can edit how the tween will work.

An example of a TweenInfo object could be:


local tweenInfo = TweenInfo.new(

0.5, -- takes 0.5 seconds to move
Enum.EasingStyle.Bounce, --  how thw tween will move
Enum.EasingDirection.Out, -- how the tween will move idk how to explain
1, -- how many times the tween will repeat
true, -- if the tween will repeat at all
0, -- the delay between tweens if it does repeat

)

1 Like

Thank you so much!!!
: DDDDDDDDD