Floating Cube(Not Working)

I’m not sure why this isn’t working.

Ion = script.Parent
local goal1 = {}
goal1.Position = Ion.Position + Vector3.new(0,2,0)
local goal2 = {}
goal2.Position = Ion.Position



local TweenService = game:GetService("TweenService")
while true do
	local tweenInfo = TweenInfo.new(2)
	local tween1 = TweenService:Create(Ion, tweenInfo, goal1)
	tween1:Play()
	local tweenInfo = TweenInfo.new(2)
	local tween2 = TweenService:Create(Ion, tweenInfo, goal2)
	tween2:Play()
end

Could someone please help me?

Make the cube either Anchored or Massless.

Did you define goal1 because goal1 doesn’t have Position value
and goal2 too
And your while true do loop will crash without a wait()

It does

local goal1 = {}
goal1.Position = Ion.Position + Vector3.new(0,2,0)
local goal2 = {}
goal2.Position = Ion.Position

It’s already anchored but thank you.

Also, if you want to make a Tween loop, I’d recommend not using a while true do loop, but rather by setting the tween to infinitely loop using TweenInfo.new().

try

local tween1 = TweenService:Create(Ion, tweenInfo,{Position = goal1.Position})

and for tween 2 too ofcourse

1 Like

do this:

Ion = script.Parent
local goal1 = {}
goal1.Position = Ion.Position + Vector3.new(0,2,0)
local goal2 = {}
goal2.Position = Ion.Position


local TweenService = game:GetService("TweenService")
while true do
	local tweenInfo = TweenInfo.new(2)
	local tween1 = TweenService:Create(Ion, tweenInfo, goal1)
	tween1:Play()
    tween1.Completed:Wait()
	local tweenInfo = TweenInfo.new(2)
	local tween2 = TweenService:Create(Ion, tweenInfo, goal2)
	tween2:Play()
    tween2.Completed:Wait()
end

Tweens don’t pause the script so the going up and down tween gets overridden. So, you have to wait until the first tween completed and then play the second one

1 Like

Tysm, for helping out. I will remember this next time.

Yes but, I ran into this problem that i dont want the tween complete, i mean, yes i want but i dont want to wait for the tween to complete, and all the parts transparency gets to 0 directly, how i would do that?, and why that “2” in tweenInfo

2 is for the length of the tween.