Need help with a script

I want player move right if he hold R on keyboard (don’t ask me why) so I know how to make it move right if he press R but idk how to make a move right if he hold R so if player hold R the character always move right but if he unhold R the player stop moving right

this is the script

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local Character = player.CharacterAdded:Wait()

local humanoid = Character:WaitForChild("Humanoid")

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:connect(function(keyCode)
	local HRP = Character:FindFirstChild("HumanoidRootPart")

	if keyCode.keyCode == Enum.KeyCode.R then
		Character:MoveTo(HRP.Position + Vector3.new(0,0,1))
	end	
end)

the character already moves right when you press d on the keyboard what are you meaning!!!

im making a running game so i made player always move forward so the player cant move right if he press D so i want to make a script to make player move right if he press R

I never Heard About that But i think is simple to do it

do some research on rightvector. it might be what your looking for.

First off, :MoveTo() is a method of Humanoid, not Character. Use Character.Humanoid to access :MoveTo().

I think I understand what you’re saying. Assuming you want the character to move right while pressing R, and for it stop when you release R, you need to utilize the MoveToFinished event. Here is some example code:

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local Character = player.CharacterAdded:Wait()

local humanoid = Character:WaitForChild("Humanoid")

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:connect(function(keyCode)
    if keyCode.keyCode ~= Enum.KeyCode.R then
         return
    end

	local humanoidRootPart = Character:FindFirstChild("HumanoidRootPart")

    local humanoid = Charcacter.Humanoid
    local con
    
    humanoid:MoveTo(humanoidRootPart.Position + Vector3.new(0,0,1))
    
    con = humanoid.MoveToFinished:Connect(function()
            if UserInputService:IsKeyDown(Enum.KeyCode.R) then
	 	               Character:MoveTo(humanoidRootPart.Position + Vector3.new(0,0,1))
            else
                       con:Disconnect()
            end
    end)
end)

What this code does is it returns if the KeyCode is not KeyCode.R, which stops the thread and prevents any code below from running. It then will grab some references to key components that we’re trying to manipulate, and then calls :MoveTo() on the humanoid. We then bind to the MoveToFinished event, which fires whenever we finished executing :MoveTo(). In that event, we check to see if we are still holding the R key down, and if so, it calls :MoveTo() again. If we’re not holding R down, we disconnect the event. The loop stops.

If this code sample doesn’t work for you, or if you have further questions, please let me know.