How to control a part with wasd and arrowkeys

Ok, so I have a part that appear when you click “V” on your keyboard, its a copy of your head I removed eveyrthing in it and in a local script I add a humanoidrootpart and a humanoid and in the rootpart thers and attachment and vectorforce and it locks your mouse and orients the part when you move your mouse so if your looking down and press “W” and want it to move in that direction

@Valkyrop you have any idea?

Yeah i have a whole script with this

local speedup = 1
local boolr = false
local booly = false
local boolf = false
local boolt = false
local boolg = false
local boolh = false
local boole = false
local boolq = false
game:GetService("UserInputService").InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.W and drex then
		boolt = true
		while boolt do
			wait(.02)
			drone.CFrame *= CFrame.new(game.Workspace.Camera.CFrame.LookVector.X * speedup,0,game.Workspace.Camera.CFrame.LookVector.Z * speedup)
		end
	end
end)
game:GetService("UserInputService").InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.W and drex then
		boolt = false
	end
end)

game:GetService("UserInputService").InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.S and drex  then
		boolg = true
		while boolg do
			wait(.02)
			drone.CFrame *= CFrame.new(-game.Workspace.Camera.CFrame.LookVector.X * speedup ,0,-game.Workspace.Camera.CFrame.LookVector.Z * speedup)
		end
	end
end)
game:GetService("UserInputService").InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.S and drex  then
		boolg = false
	end
end)
game:GetService("UserInputService").InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and drex  then
		boole = true
		while boole do
			wait(.02)
			drone.CFrame *= CFrame.new(0,0.6 * speedup,0)
		end
	end
end)
game:GetService("UserInputService").InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and drex  then
		boole = false
	end
end)
game:GetService("UserInputService").InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q and drex  then
		boolq = true
		while boolq do
			wait(.02)
			drone.CFrame *= CFrame.new(0,-0.6 * speedup,0)
		end
	end
end)
game:GetService("UserInputService").InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q  and drex then
		boolq = false
	end
end)


game:GetService("UserInputService").InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift and drex  then
		speedup = 10
	end
end)
game:GetService("UserInputService").InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift  and drex then
		speedup = 1
	end
end)

2 Likes

whats drex? is that something you had ?

ye it is an old script so i am not sure what is it but i guess it is a boolean value
Edit:
I found it and it was a boolean of appearing a drone

what do I put for speedup? or what is that, nvm I found tis a variable

if you increase it then part will move towards your camera look vector faster

sometimes it doesnt move in the right direction like if im facing a way it might go sidways while pressing w

That’s strange a bit because i had everything ok with this.
Can you send a vidio with it? btw it can be because your camera script have small offset to the left.

Can you show me local script with that camera?

            mouse.Move:Connect(function()
				if mouse.Hit.p ~= prev_mousehit then
					vrhead.CFrame = CFrame.new(vrhead.Position, Vector3.new(mouse.Hit.p.X,mouse.Hit.p.Y,mouse.Hit.p.Z))
					prev_mousehit = mouse.Hit.p
				end
			end)
			local boolt = false
			uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					boolt = true
					while boolt do
						wait(0.02)
						vrhead.CFrame *= CFrame.new(game.Workspace.Camera.CFrame.LookVector.X * 1,0,game.Workspace.Camera.CFrame.LookVector.Z * 1)
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					boolt = false
				end
			end)

Mb the problem because it is setting CFrame twice?

mouse.Move:Connect(function()
				if mouse.Hit.p ~= prev_mousehit then
					vrhead.CFrame = CFrame.new(vrhead.Position, Vector3.new(mouse.Hit.p.X,mouse.Hit.p.Y,mouse.Hit.p.Z))
					prev_mousehit = mouse.Hit.p
				end
			end)

try to select and and press control + / and then test
Edit:
I guess the problem is not there.
Mb it is because you have shiftlock or smth?

it works but then the drone doesnt turn with your camera

how can I make it so I can go down when I look down

So the problem that was before fixed?
If the previous problem is fixed try to create a bool variable and in check if the variable is true
and set this variable to false if InputBegan and set the variable to false if the InputBegan.

			local CheckBool = true
			mouse.Move:Connect(function()
				if mouse.Hit.p ~= prev_mousehit and CheckBool == true then
					vrhead.CFrame = CFrame.new(vrhead.Position,Vector3.new(mouse.Hit.p.X,mouse.Hit.p.Y,mouse.Hit.p.Z))
					prev_mousehit = mouse.Hit.p
				end
			end)
			local boolt = false
			uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					CheckBool = false
					boolt = true
					while boolt do
						wait(0.02)
						vrhead.CFrame *= CFrame.new(game.Workspace.Camera.CFrame.LookVector.X * 1,0,game.Workspace.Camera.CFrame.LookVector.Z * 1)
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					CheckBool = true
					boolt = false
				end
			end)

how would I do that in that part of the script

that other error is happing again

Oh i guess i got why it happen wait a bit ;-;
Also you can delete previous check with CheckBool.

			local cam = game.Workspace.Camera
			mouse.Move:Connect(function()
				if mouse.Hit.p ~= prev_mousehit  then
					vrhead.CFrame = CFrame.new(vrhead.Position,Vector3.new(cam.CFrame.LookVector.X,cam.CFrame.LookVector.Y,cam.CFrame.LookVector.Z) + vrhead.Position )
					prev_mousehit = mouse.Hit.p
				end
			end)
			local boolt = false
			uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					boolt = true
					while boolt do
						wait(0.02)
						vrhead.Position += Vector3.new(cam.CFrame.LookVector.X * 1,0,cam.CFrame.LookVector.Z * 1)
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					boolt = false
				end
			end)

Wait i see another trouble it would always look in spawn side let me fix that.
Edit:Fixed. I see another problem i am fixing it ;-;.

movement messed up again :frowning: dont know what to do now

my script:

local cam = game.Workspace.Camera
			mouse.Move:Connect(function()
				if mouse.Hit.p ~= prev_mousehit  then
					vrhead.CFrame = CFrame.new(vrhead.Position,Vector3.new(cam.CFrame.LookVector.X,cam.CFrame.LookVector.Y,cam.CFrame.LookVector.Z) + vrhead.Position )
					prev_mousehit = mouse.Hit.p
				end
			end)
			local boolt = false
			uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					boolt = true
					while boolt do
						wait(0.02)
						vrhead.CFrame *= CFrame.new(game.Workspace.Camera.CFrame.LookVector.X * 1,0,game.Workspace.Camera.CFrame.LookVector.Z * 1)
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					boolt = false
				end
			end)