Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my block to terrain changer script not working?

So i scripted a scripted a script where it takes the blocks in this generated model and changes it to a specific terrain type according to the color but it doesn't work please hlep

local parts = workspace.Yes:GetChildren() 
print(#parts)
for i=1,#parts do
	if parts[i].color.Value == "Grime" then
		print("ok")
		local sizer = parts[i].size 
		local pos = parts[i].CFrame game.Workspace.Terrain:FillBlock(pos,sizer,Enum.Material.Grass)
	elseif parts[i].color.Value == "Sand blue" then
		local sizer = parts[i].size 
		local pos = parts[i].CFrame game.Workspace.Terrain:FillBlock(pos,sizer,Enum.Material.Water)
	end
end

the print in line 5 dosent print anything

2 answers

I have a suggestion that might help solve your problem. Instead of going through the parts 1 by 1 like you did, try to use a in pairs loop.

i = Index, your table v = Variable, the part INISDE the table

Replace line 3:

for i, v in pairs(table) do — Replace “table” with the table of parts you have.

end — Make sure there is an end at the bottom of the new loop...

Hope this helped!

Note: I’m on mobile so some formatting and code syntax may be wrong.

I tried doing it again like this but it still has the same result

local parts = workspace.Yes:GetChildren() 
print(#parts)
for i, v in pairs(parts) do
	if v.color.Value == "Grime" then
		print("ok")
		local sizer = v.size 
		local pos = v.CFrame game.Workspace.Terrain:FillBlock(pos,sizer,Enum.Material.Grass)
	elseif parts[i].color.Value == "Sand blue" then
		local sizer = v.size 
		local pos = v.CFrame game.Workspace.Terrain:FillBlock(pos,sizer,Enum.Material.Water)
	end
end

1 comment

0

I edited my answer. You need to use "v" instead of "i"

This discussion is preserved as it was. New answers, comments, and votes are closed.