How to put a value to call a model

Hello, I would like to know how I can do so that I can be seen with the name of the model.

while true do 
	for i = 1,8 do
		script.Parent.Part[i].BrickColor = BrickColor.new("New Yeller")
		wait(0.5)
		script.Parent.Part[i].BrickColor = BrickColor.new("Really black")
	end
end

I have:
Part1
Part2

Part8

Thank.

Can you elaborate?

  • seen with the name of the model?

I have Part1 and i want :

script.Parent.Part1.BrickColor = BrickColor.new("New Yeller")
		wait(0.5)
script.Parent.Part1.BrickColor = BrickColor.new("Really black")

but do this operation with all the parts

from my understanding:

i have part…

operation with parts

In short I want to turn on a sequence of parts and turn them off but the problem here is that I don’t know how to introduce the value “i” in the call of the model.

are the parts in a model?
and what sequence, sequence do what?

I would just like to know how to introduce “i” in the script so that on turn 1 part 1 turns on and off then on turn 2 it is part 2 which turns on and off, etc…

Part(i)
Part[i]
Part"i"
Part['i']

What is the right solution?

For example, if you have models like this:

Model1
Model2
Model3

You can get them like this:

for i = 1, 3 do
    print(workspace["Model"..i]) --> Model1, Model2, Model3
end

If it’s just a number, then you need to turn the i to a string.

for i = 1, 5 do
    print(workspace[tostring(i)]) --> 1, 2, 3, 4, 5 (instances)
end

Yes, but I don’t want print I want to be able to declare it in a script…

i made a funny version

local players = game:GetService("Players")

local model = script.Parent
local cooldown = 0.5

local function Function()
	for _, part in ipairs(model:GetChildren()) do
		if part:IsA("Part") then
			for count = 1, 8 do
				if part.Name..count then
					part.Color = Color3.fromRGB(255, 255, 127)
					wait(cooldown)
					part.Color = Color3.fromRGB(0, 0, 0)
					wait(cooldown)
				end
			end
		end
	end
end

players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		Function()
	end)
end)

somebody can fix the code because i have to go to an event

Then put it in a variable,

for i = 1, 3 do
    local template = workspace["Template"..i]
    print(template) --> Template1, Template2, Template3
end

Thank !

	script.Parent["Part"..i].BrickColor = BrickColor.new("New Yeller")
	wait(0.5)
	script.Parent["Part"..i].BrickColor = BrickColor.new("Really black")

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