Hi Other Developers,
I’ve been running into this error where I’m trying to make a part bob up and down but I can’t get it to work.
Here is my code:
-- variables
local TweenSerivce = game:GetService("TweenService")
local BobAnimationInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1 , true)
-- Makes the Orb bob up and down
local newPos = Orb.Position.Y + 5
TweenSerivce:Create(Orb, BobAnimationInfo, {Position = newPos}):Play()
local TweenService = game:GetService("TweenService")
local BobAnimationInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true)
-- Makes the Orb bob up and down
TweenService:Create(Orb, BobAnimationInfo, {Position = Orb.Position + Vector3.new(0, 5, 0)}):Play()
Okay so with your “newPos” variable, you’re taking the Y value of a position and adding 5 to it. That’s cool, but you’re not actually changing that value in the positional component of the object you’re referencing so basically you’re just inserting the Y value plus five which is a number.
Now it’s giving you an error telling you that you’ve added a “double” instead of a Vector3. A double is basically the same as a “float” or a non whole number / decimal.
That’s because the Y value is probably very specific and it’s not a whole number even after adding 5
@2112Jay has your solution, this is just a breakdown
This needs to be: local newPos = Orb.Position + Vector3.new(0, 5, 0)
Vector3 is an immutable type, so you can’t change just the Y value of an existing Vector3, and if you extract just Y, you’ve got only a Number, not a Vector3 anymore. So your newPos is type Number, which is a ‘double’ in C++ (double-precision float).
This isn’t a Vector3! newpos is just a double, which is because you don’t have the rest of the x, y, and z.
here is a fix
local newPos = Orb.Position+Vector3.new(0, 5, 0) -- this works because you can add, subtract, divide, & multiply other vector3's together. You can NOT subtract and add them with only numbers..(this only applies to those two, division * multiplication are fine.