How to make a character fly?

So, I’m very new to lua scripting, and I’m confused. I’m trying to make the player’s character fly immediately after spawning, and move forward continuously, using the A and D keys to move left and right and the W and S keys to go up and down. I’ve tried numerous scripts already all over the devforum, but they either don’t work for my intents, and I can’t figure out what parts to edit to make it work, or it doesn’t work at all. I currently have a custom model as the character model as well. I need help desperately. Thanks in advance!

well, make sure you have a primary part, then use something like body position to move, and for the constant forward, this will work on the client

-- this is assuming your using body position (it does work without body position but your teleporting forward instead of moving)
while wait(.1) do
local speed = 5
bodyPos.Position = (primary.CFrame.LookVector + primary.CFrame * speed).Position
end

to get the keys use userimputservice, and yes you could also use context action service,
but i dont really see a need for that here

in a local script

local imputService = game:GetService("UserImputService")
while wait(.1) do
	local keys = imputService:GetKeysPressed()
	for _, key in pairs (keys) do
		if key.KeyCode == Enum.KeyCode.A then
		--do stuff
		elseif key.KeyCode == Enum.KeyCode.D then
		--do stuff
		elseif key.KeyCode == Enum.KeyCode.S then
		--do stuff
		elseif key.KeyCode == Enum.KeyCode.W then
		--do stuff
		end
	end
end

you could also fire a server and go through the keycodes there to but as the local
player has network control over the player, you could just handle it from the client
and do the movement from the client.

1 Like

Where should I put these scripts?

1 Like

well, i would recommend player character, (starter player → starter character scripts), but just about anywhere that can run local scripts for the player (backpack, character, player) would work