Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make only the CFrame.Y stop growing within an i-loop?

Asked by 5 years ago

I made this script that should make a wave go up, until a certain height. I succeeded in making the wave stop going up within the i-loop, but it makes the entire wave stop. I would like it to keep moving in the X-direction. How do i make sure the CFrame.X doesn't stop?

local Tsunami = script.Parent
local MaxHeigth = 44
local StartPosition = Vector3.new(-0.231, -76, 1016.603)
for i = 1,1000 do
    wait(.01)
    Tsunami.CFrame = CFrame.new(StartPosition) + Vector3.new(0,0,i*-5) + Vector3.new(0,i,0)
    if Tsunami.CFrame.Y == MaxHeigth then
        Tsunami.CFrame.Y = MaxHeigth
        Tsunami.CFrame.X = i*-5
    end
end

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Hi Zuru,

Why are you using a for loop when you can use TweenService? TweenService is much simpler to get tasks done with and much more efficient in my opinion. It would look something like this:

This Script Assumes The Necessary Variables Have Been Set

local tween_s = game:GetService("TweenService");
local ending_x, ending_y = 50, 20;
local part = workspace.Part;
local props = {Position = Vector3.new(ending_x, ending_y, part.Position.Z)};
local speed = 5; -- The amount of seconds it will take to arrive at its location.
local info = TweenInfo.new(speed, Enum.EasingStyle.Linear, Enum.EasingDirection.In);
local tween = tween_s:Create(part, info, props);

tween:Play();

Hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

0
Aha, thank you. Haven't even heard of Tweenservice before... ZURUgamer 7 — 5y
0
No problem. Glad to help. KingLoneCat 2642 — 5y
0
This script gives me just 1 problem: with the CFrames the wave would just go through colliding parts, like the ground. However with the Tweening, it acts like it collides with the ground... ZURUgamer 7 — 5y
0
Just make the wave non-collidable through properties. Set CanCollide to false. KingLoneCat 2642 — 5y
Ad

Answer this question