… You should use a TweenService
instead.
Not only is the TweenService useful for CFrame situations, like this, but it has a parameter that allows it to go for as long as you want it to.
Example using your code.
local TweenService = game:GetService("TweenService")
local TrolleyTweenInfo = TweenInfo.new(1)
...
local function TakeTrolleyAnim()
-- repeat wait(0.00001) Motor.C1 = Motor.C1 * CFrame.new(0,0,0.05) until Motor.C1 == CFrame.new(0,0,0.10) <-- this is unnecessary, since again TweenService exists. you'd be doing more work for yourself doing it this way.
local TrolleyTween = TweenService:Create(Motor, TrolleyTweenInfo, {C1 = CFrame.new(0, 0, 0.10)})
TrolleyTween:Play()
TrolleyTween.Completed:Connect:function(HideTrolley)
end
If you would like to know what is going on for each line…
-
local TrolleyTweenInfo = TweenInfo.new(1)
A TweenInfo is probably self-explanatory, but it allows you to control how long the Tween should play out. And also, control how it moves.
Here’s what parameters you could use for a TweenInfo
:
local toofoo = TweenInfo.new(
3, -- the time it takes for the tween to finish
Enum.EasingStyle.Quad, --[[ the type of motion it does during the tween.
you should read more of that here: https://developer.roblox.com/en-us/api-reference/enum/EasingStyle]]
Enum.EasingDirection.InOut, --[[ the ease it uses to do that.
if "In", then it'll be like a car building up speed.
if "Out", then it'll be like a car breaking; it slows down after you hold on the breaks for so long.
"InOut" is just the combination of both.]]
-1, --[[ this is how many times it'll repeat the tween.
-1 is to infinitely loop it, which means it will never finish.]]
true, --[[ this is for the tween to reverse after it reaches it's endpoint.
if true, it'll reverse]]
2 -- the delay time of the tween. (before it starts)
)
There's two images that allows you to see how each Enum.EasingStyle operate.
-
local TrolleyTween = TweenService:Create(Motor, TrolleyTweenInfo, {C1 = CFrame.new(0, 0, 0.10)})
This returns a Tween, that can be use to play, stop or pause the tween (that’s probably obvious).
Creating a Tween with TweenService:Create
requires the Instance
You want to be tweened, a TweenInfo
and the parameters that it should modify/change to as a table. To declare them, it’s just like getting the property of anything else.
The reason the declared instance’s (first variable in TweenService:Create) properties is in a table is, so that, you can have it change multiple values within the same tween.
-- {C1 = CFrame.new(0, 0, 0.10)} is just the same as..
Motor.C1 = CFrame.new(0, 0, 0.10)
-- {Position = Vector3.new(59, 103, 284), Size = Vector3.new(9, 7, 6)} is just the same as..
Part.Position = Vector3.new(59, 103, 284)
Part.Size = Vector3.new(9, 7, 6)
This is the type of objects that can be tweened.
- number
- bool
CFrame
Rect
Color3
UDim
UDim2
Vector2
Vector2int16
Vector3
Now, this should help you make your trolley without having to cause a headache for yourself! If anything else happens that you’re not sure of, you can PM me; Otherwise, happy coding and enjoy your day!