How to rotate a union operation with other instances?

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")

local Sentry = script.Parent
local Main_Sentry = Sentry:WaitForChild("Main_Sentry")
local Ray_Origin = Main_Sentry:WaitForChild("Ray_Origin")

local MAX_RANGE = 100
local COOLDOWN = 0.1

local function Visualizer(Origin, End_Position, Distance, LASER_COLOR)
	local Laser = Instance.new("Part")
	Laser.CanCollide = false
	Laser.CanTouch = false
	Laser.CanQuery = false
	Laser.CastShadow = false
	Laser.Anchored = true
	Laser.Color = LASER_COLOR
	Laser.Material = Enum.Material.Neon
	Laser.Size = Vector3.new(0.2, 0.2, Distance)
	Laser.CFrame = CFrame.lookAt(Origin, End_Position) * CFrame.new(Vector3.new(0, 0, -Distance/2))
	Laser.Parent = workspace
	
	Debris:AddItem(Laser, 0.1)
end

while true do
	for i, player in Players:GetPlayers() do
		local character = player.Character or player.CharacterAdded:Wait()
		local HRP = character:WaitForChild("HumanoidRootPart")
		
		local Distance = (HRP.Position - Ray_Origin.WorldCFrame.Position).Magnitude
		if Distance > MAX_RANGE then continue end
		
		local Origin = Ray_Origin.WorldCFrame.Position
		local Direction = ((HRP.Position - Main_Sentry.Position).Unit) * MAX_RANGE
		
		local RaycastParameters = RaycastParams.new()
		RaycastParameters.FilterType = Enum.RaycastFilterType.Exclude
		RaycastParameters.FilterDescendantsInstances = {Sentry}
		RaycastParameters.IgnoreWater = true
		
		local RayResults = workspace:Raycast(Origin, Direction, RaycastParameters)
		
		if not RayResults then
			print("Hit Nothing!")
		else
			print("Hit: ".. RayResults.Instance.Name)
			if RayResults.Instance.Name == "Handle" and RayResults.Instance.Parent:IsA("Accessory") and Players:GetPlayerFromCharacter(RayResults.Instance.Parent.Parent) or Players:GetPlayerFromCharacter(RayResults.Instance.Parent) then
				local LookAt_CFrame = CFrame.lookAt(Origin, RayResults.Position)
				local X, Y, Z = LookAt_CFrame:ToOrientation()
				
				Visualizer(Origin, RayResults.Position, RayResults.Distance, Color3.fromRGB(0, 255, 0))
				TweenService:Create(Main_Sentry, TweenInfo.new(0.25, Enum.EasingStyle.Linear), {Orientation = Vector3.new(math.deg(X), math.deg(Y), math.deg(Z))}):Play()
			else
				Visualizer(Origin, RayResults.Position, RayResults.Distance, Color3.fromRGB(255, 0, 0))
			end
		end
	end
	
	task.wait(COOLDOWN)
end


I’m trying to get the entire upper part of the sentry to rotate as its shooting the player but I’m not sure how to rotate the entire thing. I can only rotate one part and that’s it.

  • Put all the parts that you want to rotate together in a single Model, and then use Model.PivotTo.
  • Weld all of the parts that you want to rotate together, and then change the RootPriority of the part you want to rotate up, and all of its welded, unanchored parts will follow.


I tried to use weld constraints to weld everything part it still won’t rotate everything to face the player

The parts are unanchored, right?

If so, you can’t use those. They have to be normal welds, I think.

Yes, the parts are unanchored and I thought WeldConstraints replaced Welds?

They do not replace Welds, because when you change the CFrame of the part yourself, it changes the WeldConstraint itself.

Oh… I didn’t know that, but I’m trying to use tween service to smoothly rotate the part to look at the player

Yes, you would probably want to use welds. You will manually need to change C0 and/or C1 in each of them, but there are auto welders available, like qPerfectionWeld.

I never heard of a PerfectionWeld. What is that?

It’s a very, very old model that you can find on the toolbox made by Qwenty I believe. However, weld the parts any way you wish to do so.

You can weld this model using WeldConstraint and only have primary part (pivot part) of it anchored and having rest unanchored.

I will try using welds but I noticed something when I compared WeldConstraints and Welds.


Why is WeldConstraints like more shown while Weld is darker?

It’s because the object inserter doesn’t recommend that you parent welds there. It will only recommend it for parenting under a BasePart.

Ohhhhhhhhhhh. I didn’t know that lol

I’m trying that and it still didn’t work

Are you sure that model is welded toghether and doesnt fall apart?

Yeah it didn’t fall apart but the rectangle only moves

You need to unanchor welded part and keep part that you are moving anchored only.
Etc go to view afaik and press show welds
they should glow green.


1 Like

The part I want to rotate is anchored while the others aren’t anchored, I don’t know why it doesn’t rotate with the other parts?