Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to give a player the ability to fly?

Asked by
sheepposu 561 Moderation Voter
4 years ago

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

Log in to vote
1
Answered by 4 years ago

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.

Ad

Answer this question