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

How do you make lava/water rise smoothly?

I got a script on it to make it rise up, but the numbers are confusing to me. How can you make it move up smooth?

while true do

b = script.Parent

for i = 0, 0.1 do
b.CFrame=b.CFrame+Vector3.new(0,0.5,0)
wait()
end
wait(2)
for i = 0, 0.01 do
b.CFrame=b.CFrame+Vector3.new(0,0,0)
wait()
end
end

2 answers

✓ Accepted answer

Consider using TweenService.

Although it'd be smoother on the client end, I'd imagine this water/lava is supposed to kill players or something along the lines of that. You could use a RemoteEvent and already have instructions on the client as to how to move the part, but that may be a little risky, considering you'd be assuming the client is not deleting the part or whatever, and it would be a lot more work.

Regardless, I'm going to give you a server-end solution:

local part = game.Workspace.Part

local ts = game:GetService("TweenService")

local duration = 10
local style = Enum.EasingStyle.Linear
local direction = Enum.EasingDirection.InOut

local info = TweenInfo.new(duration, style, direction, 0, false, 0)

local startPosition = Vector3.new(0, 0, 0)
local endPosition = Vector3.new(0, 10, 0)

while true do
	wait(3)
	if part.Position == startPosition then
		local tween = ts:Create(part, info, {Position = endPosition})
		tween:Play()
		tween.Completed:Wait()
	else
		local tween = ts:Create(part, info, {Position = startPosition})
		tween:Play()
		tween.Completed:Wait()
	end
end

Now, this is just an example of what you can do.

Take what you will from it. If you need an explanation for something, shoot me a comment.

2 comments

1

Works really good, thank you for the help

0

No problem :)

You need a wait(.2) (wait for .2 sec) in For Loop without it it will move very fast (almost instantly) Also CFrame use CFrame, not Vector3, so i gonna change CFrame to Position

b = script.Parent
while wait() do
	for i = 0, 100 do
		b.Position=b.Position+Vector3.new(0,0.5,0) -- will make the brick go up 50 studs (.5 x 100 is 50, change it if u want)
		wait(.2)
	end
	wait(2)
	for i = 0, 10 do
		b.Position=b.Position+Vector3.new(0,0,0)
		wait(.2)
	end
end

3 comments

0

Still moving pretty slow, could it be the wait(2)

0

Making it wait(2) will make it slower (cause it will wait 2 sec instead of 0.2) you could make it 0.01 if u want

0

also the end value at line 3 and 8 should be >1

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