I’m trying to make a block that floats and rotates above a platform with a random orientation for each time it does it.
The issue is it tweens, but the orientation doesn’t change every time. The orientation stays at (0,0,0) for whatever reason. My code should work.
Instead of using TweenService’s built in looping tween function, I made my own in a while loop. I did this because I assumed that this was the issue, and that was why the values were not changing. Here is my code:
(Any help appreciated!)
local hi = game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0), {Orientation = Vector3.new(a,b,c), Position = Vector3.new(-70.389, 5.488, 32.02)})
while true do
wait(.9)
a = math.random(20,100)
b = math.random(-130, 0)
c = math.random(-130, 0)
wait(.1)
hi:Play()
end
Your problem is that you are trying to modify the tween after creating it along with not declaring the a, b, and c variables.
You should instead, change the settings you want to tween and create the tween inside the loop itself and then play it.
Here is the modified version of your code:
local TweenService = game:GetService("TweenService")
local TweenInformation = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0)
local Settings = {
Orientation = Vector3.new(20, -130, -130),
Position = Vector3.new(-70.389, 5.488, 32.02)
}
while task.wait(.9) do
local a = math.random(20,100)
local b = math.random(-130, 0)
local c = math.random(-130, 0)
Settings.Orientation = Vector3.new(a, b, c)
local Tween = TweenService:Create(script.Parent, TweenInformation, Settings)
task.wait(.1)
Tween:Play()
end
Nevermind I see now. One error - the block doesn’t float up and down, it just floats once and stays even though reverse is set to true in the tweeninfo. Can you please help me fix this?
Try to increase the while loop waiting time. Like two seconds…
Or
You can actually wait for the tween to complete using the Tween.Completed:Wait() method.