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

What does 'for' ; initial value must be a number mean?

What i'm doing

I'm trying to make an object in starter pack slowly move to the position of mouse when you click. I'm given the error ; 'for' initial value must be a number as an error. I don't understand.

--// "Variables" \\--



tool = script.Parent

handle = script.Parent.Handle

CPart = game.Workspace.CPart

local player = game.Players.LocalPlayer

PMouse = player:GetMouse()

m = handle.Position

m1 = PMouse.X

m2 = PMouse.Y

  

  

--// Tables \\--

  

  

  

--// Functions \\--

  

tool.Equipped:Connect(function(Jan)

PMouse.Button1Down:Connect(function()

for i = m, m1, 1 do

handle.Position = Vector3.new(i,i,i)

wait()

end

end)

end)

  

tool.Equipped:Connect(function(Feb)

PMouse.Button1Down:Connect(function()

for i = m, m2, 1 do

handle.Position = Vector3.new(i,i,i)

wait()

end

end)

end)

6 comments

0

how to lua format the whole thing it only does 1 line!??!!

1

The error basically says you didn't give numbers. you gave it Vector3s.

1

Also press Ctrl + Shift + K for a code block whilst in the editor.

0

would u answer im a little confused

0

handle.Position is a vector3 for loops want one number for the first value but you gave it 3 for the first value you should do somehing like for i = m.X, m2 do and the last value defaults to 1

0

also ur saying handle.Position = Vector3.new(handle.Position)

1 answer

✓ Accepted answer

You're setting the initial value of a for loop (variable m) to a Vector3 value. It must be a number.

for i = 0, 1, 0.1 do
	print(i)
end

will work, but

for i = Vector3.new(25,25,25), 1 do
	print(i)
end

will not work.

The initial value, the ending value, and the increment value must all be numbers.

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