How to rotate part on Y axies using mouse (plugin)

I want to rotate a part on the Y axis using my mouse (keep in mind this is for a plugin so I am using mouse = plugin:GetMouse() ).

mouse.TargetFilter = wall
wall.CFrame = CFrame.Angles(0, mouse.Hit.p.Y, 0)

When I hover my cursor over the part it rotates, but when I dont it stays the same.
I tried removing the TargetFilter but it made no difference.

1 Like

Do you mean that when your mouse isn’t over the target, it lags the game?

First thing to do is to multiply the current CFrame of wall, instead of setting it, by CFrame.Angles.


wall.CFrame *= CFrame.Angles(0, mouse.Hit.p.Y, 0)

I haven’t looked into the library you’re using because I’m on a mobile browser, but I will in a few minutes.

1 Like

No, I mean that only when my cursor is hovering over the part it rotates but when it is not hovering over the part it doesn’t rotate. I want it to rotate even when I am not hovering over the part.

1 Like

Sorry, I misread what you were saying.
There are two ways to accomplish what you want to do. The first method assumes that your mouse is locked in place on the screen, like you are in first person or holding MouseButton2 to rotate your camera. You can assign a variable to the InputChanged event that will rotate the part using the input.Delta from said event. You can also disconnect it when certain conditions are met:

local UserInputService = game:GetService("UserInputService")

local inputChanged
-- Assign event to variable so we can disconnect it later
inputChanged = UserInputService.InputChanged:Connect(function(input, processed)
	-- Do nothing if this input was processed by the game
	if processed then return end
	-- If the input is the mouse moving
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		wall.CFrame *= CFrame.Angles(0, input.Y, 0)
	end
end)

-- Disconnect
task.wait(5)
inputChanged:Disconnect()

Or what if the players mouse isn’t locked, you can do this although I don’t recommend it as the method to getting the mouse is outdated:

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local mouse = player:GetMouse()
local lastY = mouse.Y

local move
-- Assign event to variable so we can disconnect it later
move = mouse.Move:Connect(function()
	wall.CFrame *= CFrame.Angles(0, mouse.Y - lastY, 0)
	-- Update lastY for the next Move event
	lastY = mouse.Y
end)

-- Disconnect
task.wait(5)
move:Disconnect()
1 Like

This would not work because I am scripting a plugin and not a game