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
