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

How to give a player the ability to fly?

I made a script for flying but it doesn't work. If I loop the part that lifts up the player, the player falls down to the ground after lifting by 1/5 of a stud. If I put multiple together it will lift the player a higher. I don't understand why repetition of the line lifts up the player, but a loop won't lift them up. Can someone tell me what I am doing wrong to try and give the player flying abilities. One more problem is the player will always turn to a certain direction whenever I hold space to try and fly. I know it has something to do with how I'm trying to fly, but I don't know what since I don't usually work with CFrames. Here's is the code

local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local HRP = plr.Character.HumanoidRootPart
local uis = game:GetService('UserInputService')

while true do
	wait()
	if plr.Mode.Value == 'Flying' then
		while uis:IsKeyDown(Enum.KeyCode.Space) do
			wait()
			HRP.CFrame = CFrame.new(Vector3.new(HRP.Position.X, HRP.Position.Y + 0.2, HRP.Position.Z))
		end
	end
end

1 answer

✓ Accepted answer

instead of doing

HRP.CFrame = CFrame.new(Vector3.new(HRP.Position.X, HRP.Position.Y + 0.2, HRP.Position.Z))

Do:

HRP.CFrame = HRP.CFrame * CFrame.new(HRP.Position.X, HRP.Position.Y + 0.2, HRP.Position.Z)

and that should work just fine, if it doesn't work, then comment.

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