It isn't going from 1 - 52

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    GetInstanceEffect where it will tween from 1 to 52

  2. What is the issue? Include screenshots / videos if possible!
    Explained above, when I click the button its meant to tween from 1 to 52, but it starts at a random part than 1 to 52, like it would do it backwards instead of counting up.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local TweenService = game:GetService("TweenService")

-- Function to tween color
local function tweenColor(part, endColor, duration)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tween = TweenService:Create(part, tweenInfo, {Color = endColor})
	tween:Play()
end

-- Get the model and its parts
local model = game.Workspace.Neons

local function onClicked()
	local parts = model:GetChildren()
	for i = 1, 52 do
		local part = parts[i]
		if part and part:IsA("BasePart") then
			tweenColor(part, Color3.fromRGB(170, 170, 255), 1) 
			wait(1)
		end
	end
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

image
Workspace isn’t that organised but it should start from 1 then tween to 52.

You are indexing the group of neon parts.

Perhaps you mean
local part = model:FindFirstChild(tostring(i))?
rather than
local part = parts[i]

1 Like

I’ll try that, lemme see if it works.

Nearly works! Just need for it to do all 1’s in the explorer; since it’s only doing it to one of the part, I want it at the same time.

image
Kinda like this as a concept if that works.

You could just have wrote this :

local function onClicked()
	local parts = model:GetChildren()
	for i, part in pairs(parts) do
		if part and part:IsA("BasePart") then
			tweenColor(part, Color3.fromRGB(170, 170, 255), 1) 
			wait(1)
		end
	end
end

Feel free to ask me anything if u need !
I hope it helped and have a nice day !

EDIT : oops im stupid as always it will not work with my solution since it will be random … sorry

1 Like

No worries; instead of using FindFirstChild which only returns 1 object at a time, we can loop through the model and tween the parts named i.

Like this:

for i = 1, 52 do
    for _, part in ipairs(model:GetChildren()) do
        if part.Name == tostring(i) then
            tweenColor(part, Color3.fromRGB(170, 170, 255), 1) 
        end
    end)

    task.wait(1) -- change if you want idk
end

Edit: Replaced pairs with ipairs, and changed i2 to _, as per PhoenixRessusection’s more suitable suggestion

2 Likes

Perfect, works as intended, thanks!

2 Likes

I don’t understand why u dont do this :

for i = 1, 52 do
    local part = model:FindFirstChild(i)
    tweenColor(part, Color3.fromRGB(170, 170, 255), 1) 
    wait(1)
end 

Sorry if my question is stupid and have a nice day !

There are multiple parts with the same name (eg multiple parts named “1”), so FindFirstChild will only return one of those parts; the rest are skipped.

The loop ensures all parts with the relevant index as their name are tweened.

2 Likes

Oh, I understand thank u ! I missed that point ! Have a nice day !!

2 Likes

I think you should omit i2 (use _ instead) and use ipairs since pairs is for dictionaries.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.