Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

4 comments

0

Aha, thank you. Haven't even heard of Tweenservice before...

0

No problem. Glad to help.

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...

0

Just make the wave non-collidable through properties. Set CanCollide to false.

This discussion is preserved as it was. New answers, comments, and votes are closed.