Hello. I was tryna make a truck based on the Coca-Cola christmas truck.
When I tried to script the lights, it wont work.
Script:
local rgb = script.Parent
while true do
wait()
for _, PartsInModel in ipairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part" then
PartsInModel.Color = Color3.new(1, 0, 0)
wait(3)
PartsInModel.Color = Color3.new(0, 1, 0)
wait(3)
end
end
for _, PartsInModel in ipairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part2" then
PartsInModel.Color = Color3.new(0, 1, 0)
wait(3)
PartsInModel.Color = Color3.new(1, 0, 0)
wait(3)
end
end
end
Yes I made a almost similar topic but that wouldn’t even work for this situation.
You do know it’s changing the color of one light at a time, right?
Try this:
while true do
wait(3)
for _, PartsInModel in ipairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part" then
PartsInModel.Color = Color3.new(1, 0, 0)
end
end
for _, PartsInModel in ipairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part2" then
PartsInModel.Color = Color3.new(0, 1, 0)
end
end
wait(3)
for _, PartsInModel in ipairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part" then
PartsInModel.Color = Color3.new(0, 1, 0)
end
end
for _, PartsInModel in ipairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part2" then
PartsInModel.Color = Color3.new(1, 0, 0)
end
end
end
You can use BrickColor to change the colour of the parts.
local rgb = script.Parent
while true do
wait()
for _, PartsInModel in ipairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part" then
PartsInModel.BrickColor = BrickColor.new(1, 0, 0)
wait(3)
PartsInModel.Color = Color3.new(0, 1, 0)
wait(3)
end
end
for _, PartsInModel in ipairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part2" then
PartsInModel.BrickColor = BrickColor.new(0, 1, 0)
wait(3)
PartsInModel.BrickColor = BrickColor.new(1, 0, 0)
wait(3)
end
end
end
pairs() should work better then ipairs()
pairs() allows you to see the list.
ipairs() allows you to print the list.
while true do
wait(3)
for _, PartsInModel in pairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part" then
PartsInModel.Color = Color3.new(1, 0, 0)
end
end
for _, PartsInModel in pairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part2" then
PartsInModel.Color = Color3.new(0, 1, 0)
end
end
wait(3)
for _, PartsInModel in pairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part" then
PartsInModel.Color = Color3.new(0, 1, 0)
end
end
for _, PartsInModel in pairs(rgb:GetChildren()) do
if PartsInModel:IsA("Part") and PartsInModel.Name == "Part2" then
PartsInModel.Color = Color3.new(1, 0, 0)
end
end
end