I made something that changes the properties of all parts in a model, but it only does it for 1 child. And I can’t seem to find the solution.
for i,v in pairs(Tiles.ChosenTiles:GetChildren()) do
if TileEffect == "Cheesed" then
v.Color = Color3.fromRGB(230, 200, 80)
elseif TileEffect == "Greased" then
v.Color = Color3.fromRGB(102, 63, 50)
v.Material = "Slate"
elseif TileEffect == "Spawner" then
v.Color = Color3.fromRGB(122, 190, 227)
elseif TileEffect == "Munitions" then
v.Color = Color3.fromRGB(0, 106, 0)
elseif TileEffect == "Radiation" then
v.Color = Color3.fromRGB(0, 255, 0)
v.Material = "Neon"
elseif TileEffect == "Stars" then
v.Color = Color3.fromRGB(29, 29, 29)
end
wait(20)
v.Color = Color3.fromRGB(163, 162, 165)
v.Material = "SmoothPlastic"
end
It’s because of the wait(20)
in your code, it makes a change to one part and then waits 20 seconds before changing the part again and going to the next part. I think your solution would be to coroutine it
for _,v in pairs(Tiles.ChosenTiles:GetChildren()) do
coroutine.wrap(function()
if TileEffect == "Cheesed" then
v.Color = Color3.fromRGB(230, 200, 80)
elseif TileEffect == "Greased" then
v.Color = Color3.fromRGB(102, 63, 50)
v.Material = "Slate"
elseif TileEffect == "Spawner" then
v.Color = Color3.fromRGB(122, 190, 227)
elseif TileEffect == "Munitions" then
v.Color = Color3.fromRGB(0, 106, 0)
elseif TileEffect == "Radiation" then
v.Color = Color3.fromRGB(0, 255, 0)
v.Material = "Neon"
elseif TileEffect == "Stars" then
v.Color = Color3.fromRGB(29, 29, 29)
end
wait(20)
v.Color = Color3.fromRGB(163, 162, 165)
v.Material = "SmoothPlastic"
end)()
end
3 Likes
I know this has been solved, but I’d (personally) use a delay function here, over coroutines. Just another option when you run into things like this
for i,v in pairs(Tiles.ChosenTiles:GetChildren()) do
if TileEffect == "Cheesed" then
v.Color = Color3.fromRGB(230, 200, 80)
elseif TileEffect == "Greased" then
v.Color = Color3.fromRGB(102, 63, 50)
v.Material = "Slate"
elseif TileEffect == "Spawner" then
v.Color = Color3.fromRGB(122, 190, 227)
elseif TileEffect == "Munitions" then
v.Color = Color3.fromRGB(0, 106, 0)
elseif TileEffect == "Radiation" then
v.Color = Color3.fromRGB(0, 255, 0)
v.Material = "Neon"
elseif TileEffect == "Stars" then
v.Color = Color3.fromRGB(29, 29, 29)
end
delay(20, function()
v.Color = Color3.fromRGB(163, 162, 165)
v.Material = "SmoothPlastic"
end)
end
1 Like