How do i make a flying script?

Oh but one final detail: My character jitters while standing on the ground and tps in the air when i switch tabs for a few secs.

Oh! Well just add Player.Character:WaitForChild("HumanoidRootPart").Velocity *= Vector3.new(1, 0, 1) right after the code to move up.

The renderstepped or the other one?

To the other one, then replace the renderstepped one with move(delta)

Now im flyin’ up like its in outer space :laughing:. Heres the code

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
Player.CharacterAdded:Wait()
local hrp = Player.Character:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")
local KeyFlags = {
	P = false
}

function move(delta)
	game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").CFrame *= CFrame.new(Vector3.new(0, 10*delta, 0))
	Player.Character:WaitForChild("HumanoidRootPart").Velocity *= Vector3.new(1, 0, 1)
end

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end

	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.P then
			move(1)
		end
	end
end)

RunService.RenderStepped:Connect(function(delta)
	move(delta)
end)

You need to put an if statement around move(delta).

like if move(delta) ? or smth else.

Like

if something then
	move(delta)
end

What am i gonna put in something?. Also sorry for not understanding anything, im a beginner.

Put KeyFlags.P in something. You’ll need to change that variable basedon if you’re holding P or not.

k. i did it. now how do i make that detect when i hold p and repeat it?

On inputbegan, just replace the move(1) with KeyFlags.P = true. Then just copy paste the whole function but change InputBegan to InputEnded and replace true with false.

where in the script do i put the copied function in?

Put it right after the original.

like this?

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end

	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.P then
			KeyFlags.P = true
		end
--Here i am gonna put the script.
	end
end)
In between which end?

No, it goes after the end), outside the function.

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end

	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.P then
			KeyFlags.P = true
		end
	end
end)
--Here i am gonna put the script

Works great!. Thanks!. It is now completed.

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