How can I make this enable from the right instead of the left?

I am having trouble thinking of a way to have it start from the right instead of the left side. I’m trying not to enable it manually (One particle at a time) but instead have a more simpler option. Is there any way to combat this?

Video:

I want it to be going to the right instead of the left

Code:

local RunService = game:GetService("RunService")
local FireFolder = game.Workspace.FireFolder
local Button = script.Parent
local Sound = script.Parent.Parent.Parent.Parent.Sound
local StageFire = game.Workspace.FireFolder


local function leftClick()
	Sound:Play()
	for i,v in pairs(StageFire:GetChildren()) do 
		wait()
		v.Fire.Enabled = true
		v.Sound:Play()
		wait(0.3)
		v.Fire.Enabled = false
	end
end
script.Parent.MouseButton1Click:Connect(leftClick)

You can invert the array to achieve this.

New code:

local Button = script.Parent
local Sound = Button.Parent.Parent.Parent.Sound
local StageFire = workspace.FireFolder

script.Parent.MouseButton1Click:Connect(function()
	Sound:Play()

	local invertedTable = {}

	for i = #StageFire:GetChildren(), 1, -1 do
		local stageFire = StageFire:GetChildren()[#StageFire:GetChildren()]
		table.insert(invertedTable, stageFire)
	end

	for i, v in ipairs(invertedTable) do 
		task.wait()
		v.Fire.Enabled = true

		v.Sound:Play()

		task.wait(0.3)
		v.Fire.Enabled = false
	end
end)

It did work and it starts from Pyro6 but after it finishes at Pyro1 it plays again another time?

Try this:

local Button = script.Parent
local Sound = Button.Parent.Parent.Parent.Sound
local StageFire = workspace.FireFolder

local function InvertTable(array)
	for i = 1, math.floor(#array/2) do
		array[i], array[#array - (i - 1)] = array[#array - (i - 1)], array[i]
	end

	return array
end

script.Parent.MouseButton1Click:Connect(function()
	Sound:Play()

	local invertedTable = InvertTable(StageFire:GetChildren())

	for i, v in ipairs(invertedTable) do 
		task.wait()
		v.Fire.Enabled = true

		v.Sound:Play()

		task.wait(0.3)
		v.Fire.Enabled = false
	end
end)
1 Like

GetChildren's order is technically undefined but you can use the following to iterate over an array backwards.

script.Parent.MouseButton1Click:Connect(function()
	Sound:Play()
	local Stages = StageFire:GetChildren()
	for Index = #Stages, 1, -1 do
		local Stage = Stages[Index]
		Stage.Fire.Enabled = true
		Stage.Sound:Play()
		task.wait(0.3)
		Stage.Fire.Enabled = false
	end
end)