I couldn't explain it very well in the title, so here's a much more specific description. What I want to do is have something like 10 small parts that sprout from the ground, one by one, towards where the player is looking. That, I can do very simply, and it looks a bit like this:
for i = 1,10 do x = Instance.new("Part", game.Workspace) x.Anchored = true x.CanCollide = false --bla bla bla surfaces and sizes and stuff x.CFrame = player.Character.Torso.CFrame * CFrame.new(0, 0, -i * 3) game.Debris:AddItem(x, 3) wait(.1) end
So that's the easy part. But what I need is for each part to change colors based on the ground they "sprout" from. So, my problem is that I can set the color to whatever I want, but if, let's say, the first half of them are on a Green Surface and the second half are on a Blue surface, every part will still be green, rather than changing the last half to blue.
It's rather complicated (to me... I could be missing something and it could actually be very easy, I have no idea.), but I've been stuck on this for quite some time, so I need a bit of help. Any ideas?
One solution is to check the color of the ground by raycasting:
for i = 1,10 do local x=Instance.new("Part") x.Anchored=true x.CanCollide=false --surfaces and sizes and stuff local cf=player.Character.Torso.CFrame*CFrame.new(0, 0,-i*3) x.CFrame=cf local part=workspace:FindPartOnRay(Ray.new(cf.p,Vector3.new(0,-100,0))) if part then x.BrickColor=part.BrickColor end x.Parent=workspace game.Debris:AddItem(x,3) wait(.1) end
This will check for the first part below the position the new part will be placed up to 100 studs down and set the new part's color to the color of the detected part before adding it to workspace.