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

Why is my loop not working?

Asked by 8 years ago

I'm working on a script that moves a part a certain distance more than the last part, but it keeps giving me the error code "Workspace.tileinfo:40: bad argument #2 to '?' (Vector3 expected, got number)"

function mapgen()
    local vector = 0, 0, 0
    for i = 1, mapsize do
        makenewtile()
        local lsample = sample
        local vector = lsample + 2, 0, 0 -- this is line 40
        game.Workspace.Model:MoveTo(Vector3.new(vector))
        sample = game.Workspace.Model.PrimaryPart.Position
        lsample = vector -- don't worry about this please i know how to fix it
        print(i)
        i = i + 1
    end
end

1 answer

Log in to vote
0
Answered by 8 years ago

You forgot to instantiate a new Vector3 object. All you're doing is reassigning the vector variable multiple times. Here's a corrected version:

function mapgen()
    local vector = Vector3.new(0, 0, 0)
    for i = 1, mapsize do
        makenewtile()
        local lsample = sample
        local vector = Vector3.new(lsample + 2, 0, 0) -- this is line 40
        game.Workspace.Model:MoveTo(vector)
        sample = game.Workspace.Model.PrimaryPart.Position
        lsample = vector -- don't worry about this please i know how to fix it
        print(i)
        i = i + 1
    end
end
Ad

Answer this question