Part does not go up when input is pressed

You can write your topic however you want, but you need to answer these questions:
Hi, i want to make a part the goes up when a button is pressed. But the part does not go up.

local redPart = game.Workspace.R
UIS = game:GetService("UserInputService")


local function onInputbegan(input, gameProcessed)
	if input.UserinputType == Enum.UserInputType.MouseButton3 then
		for count = 1,10 do 

			wait()
			redPart.CFrame = CFrame.new(redPart.Position) + Vector3.new(0,1,0)

		end
	end
end
``
Can someone help me with this simple problem.

You never connected the function to an event.

UIS.InputBegan:Connect(onInputBegan)

You can try modifying the velocity instead, also it doesn’t seem you’re like you’re using input correctly.

-- Services
local UserInputService = game:GetService("UserInputService")

-- Reference
local redPart = workspace:WaitForChild("R")

local function onInputBegan(inputObject, gameProcessed)
  if gameProcessed then return end
  local key = inputObject.KeyCode

  if inputObject.UserInputType == Enum.UserInputType.MouseButton3 then
    redPart.AssemblyLinearVelocity = Vector3.new(0, 1, 0)
  end
end

UserInputService.InputBegan:Connect(onInputBegan)

This does not work because you’re not calling the function. I’d suggest using TweenService to tween it smoothly instead of a loop. If you want this to be seen by everyone, consider using a RemoteEvent.

thanks but this does not work the part still does nothing

thanks i will try to use tweenservice for it

Also, you made a typo here:

if input.UserinputType == Enum.UserInputType.MouseButton3 then

The I needs to be a capital.

Are you running the code in a local script? I had a chance to test the code, it’s working but the force on the velocity is just low.

Might need to do

redPart.AssemblyLinearVelocity = Vector3.new(0, redPart:GetMass() * workspace.Gravity, 0)

Yes it is in a local script i will try it out

Possibly try running in on the server by using a RemoteEvent. Check if that might work.

Is this right? because it still does not work

-- Services
local UserInputService = game:GetService("UserInputService")

-- Reference
local redPart = workspace:WaitForChild("R")

local function onInputBegan(inputObject, gameProcessed)
	if gameProcessed then return end
	local key = inputObject.KeyCode

	if inputObject.UserInputType == Enum.UserInputType.MouseButton3 then
		redPart.AssemblyLinearVelocity = Vector3.new(0, redPart:GetMass() * workspace.Gravity, 0)
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

At first glance, yes; though I would remove local key = inputObject.KeyCode if you’re not using it.

Having the key there doesn’t hurt. It’s for future purposes if you actually want to get the key easier. Though removing it won’t hurt either.

@younis2811 So I was testing it out a bit to see why it wasn’t working. It only works if you have network ownership over the part. For now I opted to create the object on the client.

-- Services
local UserInputService = game:GetService("UserInputService")

-- Reference
local redPart = Instance.new("Part")
redPart.Name = "R"
redPart.CFrame = CFrame.new(5.953, 79.223, 16.937)
redPart.Parent = workspace

local function onInputBegan(inputObject, gameProcessed)
  if gameProcessed then return end
  local key = inputObject.KeyCode

  if inputObject.UserInputType == Enum.UserInputType.MouseButton3 then
	print("Working")
    redPart.AssemblyLinearVelocity = Vector3.new(0, redPart:GetMass() * workspace.Gravity/60, 0)
  end
end

UserInputService.InputBegan:Connect(onInputBegan)

Edit: You might want to adjust the CFrame as your environment may be different from mine.

It is good practice to remove unnecessary lines of code, especially if you are confused. Though this is just my habit.