Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my block to terrain changer script not working?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago

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

0
I edited my answer. You need to use "v" instead of "i" ThatDevTim 188 — 4y

Answer this question