How do i create part that auto rotate to target part?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I need do part auto rotate to Humanoid or other where mousepos
  2. What is the issue? Include screenshots / videos if possible!
    I typed code but doesnt work no errors
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i tried a lot didnt help, i didnt found
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
    If u didnt understand ask me
local remote = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("RemoteEvent")

local Tool = script.Parent

local TS = game:GetService("TweenService")

local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")

local mouse = Player:GetMouse()


local Touched = false



local function rotateCharacterToMouse()
	local targetPosition = mouse.Hit.Position 

	local direction = (targetPosition - Player.Character.HumanoidRootPart.Position).unit 

	local lookVector = Vector3.new(direction.X, 0, direction.Z)

	Player.Character.HumanoidRootPart.CFrame = CFrame.lookAt(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.Position + lookVector)
end

Tool.Activated:Connect(function()
	rotateCharacterToMouse()
	remote:FireServer(mouse.Hit,script.Parent.Handle)

end)	
Local Script
-----------------
Server Script
-------------------
local RS = game:GetService("ReplicatedStorage")

local remote = RS:WaitForChild("Remotes"):WaitForChild("RemoteEvent")

local levikor = RS:WaitForChild("Effects"):WaitForChild("Hit FX"):WaitForChild("Levikor"):Clone()

local Players = game:GetService("Players")

local Touched = false

remote.OnServerEvent:Connect(function(player,mousepos,Tool)
	local Part = Instance.new("Part")
	local attch = Instance.new("Attachment")
	local LV = Instance.new("LinearVelocity")
	Part.CFrame = Tool.CFrame
	Part.CanCollide = false
	Part.Parent = workspace

	game.Debris:AddItem(Part,2)
	Part.Touched:Connect(function(hit)
		if player.Character:FindFirstChild("HumanoidRootPart") == hit.Parent:FindFirstChild("HumanoidRootPart") then return end
		print(hum)
		local EHUMRP = hit.Parent:FindFirstChild("HumanoidRootPart")
		local EHUM = hit.Parent:FindFirstChild("Humanoid")
		if EHUMRP and Touched == false  then
		local particle2 = levikor.Attachment:Clone()
	    for _, particle in pairs(particle2:GetChildren())  do
			if particle:IsA("ParticleEmitter") then
				particle2.Parent = EHUMRP
				particle:Emit(particle:GetAttribute("EmitCount"))
			end
			 game.Debris:AddItem(particle,0.8)
		end

			
			Touched = true
			attch.Parent = EHUMRP
			LV.Parent = EHUMRP
			LV.Attachment0 = attch
			LV.MaxForce = 9999999
			LV.VectorVelocity = player.Character.PrimaryPart.CFrame.LookVector * 100
			game.Debris:AddItem(attch,0.4)
			game.Debris:AddItem(LV,0.4)
			print("Touched player")
			task.delay(0.6,function()
				Touched = false
				
				
	            local speed = 50
				local attack_part = Part
				local target_part = mousepos
				print(target_part)
				print(attack_part)

				while true do
					local wait_time = task.wait() 
					local distance = (target_part.Position - attack_part.Position).Magnitude
					local calculated_move = (target_part.Position - attack_part.Position).Unit * speed * wait_time
					if calculated_move > distance then
						attack_part.CFrame += target_part.Position - attack_part.Position
						break 
					else
						attack_part.CFrame = CFrame.new(attack_part.Position + calculated_move, target_part.Position)
						print(distance)
						print(calculated_move)
						print(wait_time)
					end
				end
			end)
		end
	end)	
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

Any help? i dont know how do it

1 Like

It was a bit hard to read your code, but I believe you should set this to target_part. Anytime you set the position make sure to either use CFrame or set its orientation seperately as position doesn’t set orientation.

1 Like