Making player slowly fly up

Hi, I’m attempting to make a script that gradually makes the player fly up, so that its smooth, but I’m not quite sure how to do that. Could anyone help me out? This is my code so far. It works, but I want the player to be able to go down, but I’m not sure how to disconnect the .Stepped.

local remote = script.Parent

remote.OnServerEvent:Connect(function(player)
	local char = player.Character
	local velocity = char.LinearVelocity
	local moved = 0
	
	local step = game:GetService("RunService").Stepped:Connect(function(t, dt)
		if moved <= 200 then
			moved += 1
			velocity.LineVelocity += 0.5
			print(velocity.LineVelocity)
		end
	end)
end)

When do you want the player to go down?

Couldn’t you Tween the HumanoidRootPart’s CFrame?

Sorry, its binded to a button in the local script above it, so when they reach the “max” height it reverses.

That wouldn’t abide by physics and wouldn’t look as good if done server-side like how OP did it.

I would, but I need the player to be able to walk around while being up there, and I can do that with LinearVelocity

Try this:

local remote = script.Parent

remote.OnServerEvent:Connect(function(player)
	local char = player.Character
	local velocity = char.LinearVelocity
	local moved = 0
	
	local stepConnection = nil
	
	stepConnection = game:GetService("RunService").Stepped:Connect(function(t, dt)
		if moved <= 200 then
			moved += 1
			velocity.LineVelocity += 0.5
			print(velocity.LineVelocity)
		else
			stepConnection:Disconnect()
			stepConnection = nil
		end
	end)
end)

That worked, thank you, my brain isn’t quite on right now. Such a simple fix

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.