Rotating a part when A/D key gets pressed

Oh wait I messed up onesec I will make a new script

local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local rotSpeed = 0

uis.InputBegan:Connect(function(input,gpe)
    if gpe then return; end

    if input.KeyCode == Enum.KeyCode.A then
        rotSpeed = -2 --// If -5 makes it go wrong way just change it
    end
end)

uis.InputBegan:Connect(function(input,gpe)
    if gpe then return; end

    if input.KeyCode == Enum.KeyCode.D then
        rotSpeed = 2 --// If it goes wrong way change this number
    end
end)

uis.InputEnded:Connect(function(input,gpe)
    if gpe then return; end

    if input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then
        rotSpeed = 0
    end
end)

rs.RenderStepped:Connect(function()
    workspace["PartNameHere"].Orientation += Vector3.new(rotSpeed,0,0) --// If it rotates too fast add a /10 or /100 btw and also tell me if it goes correct way
end)

NOW copy the script it should be working fine now!

It kinda works now but when I release the A or D button it still rotates untill it is vertical positioned. And it needs to stop directly at the rotation if the player releases the button.

1 Like

One second is their 3 uis.InputBegan? Or do you have a uis.InputEnded in it also make sure your not in the chat look back at my script and copy it I made a typo

WAIT I KNOW WHY LEMME DO A NEW SCRIPT OKAY? Cap lock-

So add a new RemoteEvent into ReplicatedStorage

local reps = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local rotSpeed = 0

uis.InputBegan:Connect(function(input,gpe)
    if gpe then return; end

    if input.KeyCode == Enum.KeyCode.A then
        rotSpeed = -2 --// If -5 makes it go wrong way just change it
    end
end)

uis.InputBegan:Connect(function(input,gpe)
    if gpe then return; end

    if input.KeyCode == Enum.KeyCode.D then
        rotSpeed = 2 --// If it goes wrong way change this number
    end
end)

uis.InputEnded:Connect(function(input,gpe)
    if gpe then return; end

    if input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then
        rotSpeed = 0
    end
end)

rs.RenderStepped:Connect(function()
    reps:WaitForChild("RemoteEventNameHere"):FireServer(rotSpeed)
end)

Now add a ServerScript in ServerScriptService

game.ReplicatedStorage["RemoteEventNameHere"].OnServerEvent:Connect(function(player,speed)
    workspace["PartNameHere"].Orientation += Vector3.new(speed,0,0) --// If it rotates too fast add a /10 or /100 btw and also tell me if it goes correct way
end)

The problem was you were rotating It in the client which doesnā€™t happen on the server.

Now when I try to let the part go up with E key it goes up a little bit and then teleports back to the position the part was.

Can you send me a video please henrydanger

I tested it right now and it doesnā€™t TP back, can you send me all the code in the scripts your using and where theyā€™re located

local inputService = game:GetService("UserInputService")

local vel = game.Workspace.Part.BodyVelocity
local bg = game.Workspace.Part.BodyGyro
local pressed = false

local up = 0
local upSpeed = 5

local part = game.Workspace.Part

local bodyPos = Instance.new("BodyPosition")
bodyPos.Parent = game.Workspace.Part

inputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E then

			pressed = true
			vel.Velocity = Vector3.new(0,5,0)


		end
	end
end)

inputService.InputEnded:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		pressed = false
		if pressed == false then
			vel.Velocity = Vector3.new(0,0,0)
		end
	end
end)

inputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Q then

			pressed = true
			vel.Velocity = Vector3.new(0,-5,0)
		end
	end
end)

inputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if pressed == false then
			vel.Velocity = Vector3.new(0,0,0)
		end
	end
end)

local reps = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local rotSpeed = 0

uis.InputBegan:Connect(function(input,gpe)
	if gpe then return; end

	if input.KeyCode == Enum.KeyCode.A then
		rotSpeed = -2 --// If -5 makes it go wrong way just change it
	end
end)

uis.InputBegan:Connect(function(input,gpe)
	if gpe then return; end

	if input.KeyCode == Enum.KeyCode.D then
		rotSpeed = 2 --// If it goes wrong way change this number
	end
end)

uis.InputEnded:Connect(function(input,gpe)
	if gpe then return; end

	if input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then
		rotSpeed = 0
	end
end)

rs.RenderStepped:Connect(function()
	reps:WaitForChild("DroneEvent"):FireServer(rotSpeed)
end)
game.ReplicatedStorage["DroneEvent"].OnServerEvent:Connect(function(player,speed)
	workspace["Part"].Orientation += Vector3.new(speed,0,0) --// If it rotates too fast add a /10 or /100 btw and also tell me if it goes correct way
end)

Donā€™t use a body Velocity Copy and Paste the entire script I sent in the LocalScript same as Body Position

I pasted your entire script so I donā€™t really understand it. Or do you mean only that you send and delete the rest?

Like make the entire LocalScript empty and just paste this in it

local reps = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local rotSpeed = 0

uis.InputBegan:Connect(function(input,gpe)
    if gpe then return; end

    if input.KeyCode == Enum.KeyCode.A then
        rotSpeed = -2 --// If -5 makes it go wrong way just change it
    end
end)

uis.InputBegan:Connect(function(input,gpe)
    if gpe then return; end

    if input.KeyCode == Enum.KeyCode.D then
        rotSpeed = 2 --// If it goes wrong way change this number
    end
end)

uis.InputEnded:Connect(function(input,gpe)
    if gpe then return; end

    if input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then
        rotSpeed = 0
    end
end)

rs.RenderStepped:Connect(function()
    reps:WaitForChild("RemoteEventNameHere"):FireServer(rotSpeed)
end)

Your BodyVel and BodyPos it breaking it

Ok, but how do I make it go up now? Cause I removed the BodyVelocity.

Copy and paste this and put it into your script your script should only have this
local reps = game:GetService(ā€œReplicatedStorageā€)
local uis = game:GetService(ā€œUserInputServiceā€)
local rs = game:GetService(ā€œRunServiceā€)
local rotSpeed = 0

uis.InputBegan:Connect(function(input,gpe)
if gpe then return; end

if input.KeyCode == Enum.KeyCode.A then
    rotSpeed = -2 --// If -5 makes it go wrong way just change it
end

end)

uis.InputBegan:Connect(function(input,gpe)
if gpe then return; end

if input.KeyCode == Enum.KeyCode.D then
    rotSpeed = 2 --// If it goes wrong way change this number
end

end)

uis.InputEnded:Connect(function(input,gpe)
if gpe then return; end

if input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then
    rotSpeed = 0
end

end)

rs.RenderStepped:Connect(function()
reps:WaitForChild(ā€œRemoteEventNameHereā€):FireServer(rotSpeed)
end)

Still doesnā€™t makes the part go up with E or Q

Itā€™s using A and D as the keybinds dude not E and Q

Yes I know but now it can only ROTATE and not go up/down itā€™s a drone.