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

Why is my loop not working?

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

✓ Accepted answer

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

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