Don't mind the scripting, its correct. But the animation is Sloppy. How would i make it more "ongoing"
gui.Parent = player.Character.Head wait(0.25) gui.ExtentsOffset = Vector3.new(0,5,0) wait(0.25) gui.ExtentsOffset = Vector3.new(0,6,0) wait(0.25) gui.ExtentsOffset = Vector3.new(0,7,0) wait(0.25) gui.ExtentsOffset = Vector3.new(0,8,0) wait(4) gui.Parent = nil end
What you want to use is a Numeric For-Loop
According to the Lua 5.0 documentation (available online)
A numeric for has the following syntax:
for var=exp1,exp2,exp3 do something end
That loop will execute something for each value of var from exp1 to exp2, using exp3 as the step to increment var. This third expression is optional; when absent, Lua assumes one as the step value.
For example, doing
for i=2,10,1 do print(i) end
will print:
2 3 4 5 6 7 8 9 10
Because we are printing i
, which starts at 2
, and we are also adding 1
to i
until we reach 10
. Going back to the Lua Documentation:
This third expression is optional; when absent, Lua assumes one as the step value.
This means that we can omit 1
from the for-loop (so it will be for i=2, 10 do
)and it will still print the same values.
That's cool and all, but how would I use it?
Given your original script, it looks like you want to smoothly animate the gui from Vector3.new(0,5,0)
to Vector3.new(0,8,0)
in one second. Four seconds after that, you want to set its Parent to nil. You would execute a for-loop that looks something like this:
gui.Parent = player.Character.Head -- a wait() is roughly 1/30th of a second. wait() is the shortest pause you can do without using RunService. for i = 5, 8, 1/30 do -- sets ExtentsOffset.Y to i, which is animated from 5 to 8 gui.ExtentsOffset = Vector3.new(0,i,0) wait() end gui.ExtentsOffset = Vector3.new(0,8,0) wait(4) gui.Parent = nil
Please not that the animation will not take exactly one second, but it should be roughly the same. For animations that take exactly one second, you will have to do delta timing, which is a complex topic outside the scope of this question.
Smaller intervals. Just make it wait less and move less, and it will be less jumpy. It would be a good idea to learn how to use a for loop at this point.