Vector3 doesn't work with welds/Motor6Ds

I’m trying to weld the head of my light to a part.
However, when I use vector3 to change the orientation of the light, the parts don’t move.

Here’s the code (segmented)

local TweenService = game:GetService("TweenService")
local Body = script.Parent["Body"]
local PrimaryPart = Body.Head["Primary"]
local Pan = Body.Pan["BasePart"]
local target = workspace.Target

local lens = Body.Head["Lens"]

local TargettingModeEnabled = false
local PausedForTweening = false

function Move(Speed, CFrameValue, Target) -- Target only used if TargettingModeEnabled is on.
	local tweenInfo = TweenInfo.new(Speed)
	local tween
	
	if TargettingModeEnabled then
		tween = TweenService:Create(PrimaryPart, tweenInfo, {CFrame = CFrame.lookAt(PrimaryPart.Position, Target.Position)})
	else
		tween = TweenService:Create(PrimaryPart, tweenInfo, {Orientation = CFrameValue})
	end
	
	if tween then
		PausedForTweening = true
		
		tween:Play()
		tween.Completed:Wait()
		
		PausedForTweening = false
	end
end

while task.wait(0.5) do
	Move(0.5, Vector3.new(PrimaryPart.Orientation.X, PrimaryPart.Orientation.Y + 90, PrimaryPart.Orientation.Z), nil)
end

Please let me know if you know why this is happening! All responses are appreciated!

2 Likes

To move and orient the “PrimaryPart” correctly, you can adjust your code like this:

local TweenService = game:GetService("TweenService")
local Body = script.Parent["Body"]
local PrimaryPart = Body.Head["Primary"]
local Pan = Body.Pan["BasePart"]
local target = workspace.Target

local lens = Body.Head["Lens"]

local TargettingModeEnabled = false
local PausedForTweening = false

function RotateTo(CF, Speed)
    local tweenInfo = TweenInfo.new(Speed)
    local tween = TweenService:Create(PrimaryPart, tweenInfo, {CFrame = CF})
    
    if tween then
        PausedForTweening = true
        tween:Play()
        tween.Completed:Wait()
        PausedForTweening = false
    end
end

while wait(0.5) do
    -- Create the desired CFrame rotation here
    local desiredRotation = CFrame.Angles(0, math.rad(90), 0) -- Rotate 90 degrees around the Y-axis
    
    -- Rotate to the desired orientation
    RotateTo(desiredRotation, 0.5)
end

In this code, I’ve defined a RotateTo function that properly uses the TweenService to change the orientation (CFrame) of your “PrimaryPart.” The desiredRotation variable is set to the desired orientation, and it rotates the part 90 degrees around the Y-axis. You can adjust the orientation as needed. Just replace this part of the code with your desired rotation.

1 Like

This post might help

Hi! Thank you for the response, however I believe you misunderstand my question. The primaryPart is rotating correctly, the problem is that the parts that are attached to it (HazeBeam, Lens, Part) are not moving.

Thanks! However, it’s not tweening a model. It’s tweening a part that has a few other parts attached to it.
image

Try this:

local TweenService = game:GetService("TweenService")
local Body = script.Parent["Body"]
local PrimaryPart = Body.Head["Primary"]
local Pan = Body.Pan["BasePart"]
local target = workspace.Target
local lens = Body.Head["Lens"]
local Part = Body.Head["Part"] -- add the missing part to rotate

local TargettingModeEnabled = false
local PausedForTweening = false

function RotateTo(part, CF, Speed)
    local tweenInfo = TweenInfo.new(Speed)
    local tween = TweenService:Create(part, tweenInfo, {CFrame = CF})
    
    if tween then
        PausedForTweening = true
        tween:Play()
        tween.Completed:Wait()
        PausedForTweening = false
    end
end

while wait(0.5) do
    -- create the desired CFrame rotation here
    local desiredRotation = CFrame.Angles(0, math.rad(90), 0) -- Rotate 90 degrees around the Y-axis
   
    RotateTo(PrimaryPart, desiredRotation, 0.5)
    RotateTo(lens, desiredRotation, 0.5)
    RotateTo(Part, desiredRotation, 0.5)
    
    -- if Pan needs to be rotated as well, add it here
    -- RotateTo(Pan, desiredRotation, 0.5)
end
1 Like


As you can see, it’s moving the light in an incorrect way.

local TweenService = game:GetService("TweenService")
local Body = script.Parent["Body"]
local PrimaryPart = Body.Head["Primary"]
local Pan = Body.Pan["BasePart"]
local target = workspace.Target
local lens = Body.Head["Lens"]
local Part = Body.Head["Part"] -- add the missing part to rotate

local TargettingModeEnabled = false
local PausedForTweening = false

function RotateTo(part, CF, Speed)
    local tweenInfo = TweenInfo.new(Speed)
    local tween = TweenService:Create(part, tweenInfo, {CFrame = CF})
    
    if tween then
        PausedForTweening = true
        tween:Play()
        tween.Completed:Wait()
        PausedForTweening = false
    end
end

while wait(0.5) do
    -- create the desired CFrame rotation here
    local desiredRotation = CFrame.Angles(0, math.rad(90), 0) -- Rotate 90 degrees around the Y-axis
   
    RotateTo(PrimaryPart, desiredRotation, 0.5)
    RotateTo(lens, desiredRotation, 0.5)
    RotateTo(Part, desiredRotation, 0.5)
    
    -- if Pan needs to be rotated as well, add it here
    -- RotateTo(Pan, desiredRotation, 0.5)
end

Did you add everything I said to add, or just copy and paste?

This is the full code:

local TweenService = game:GetService("TweenService")
local Body = script.Parent["Body"]
local PrimaryPart = Body.Head["Primary"]
local Pan = Body.Pan["BasePart"]
local target = workspace.Target
local lens = Body.Head["Lens"]
local Part = Body.Head["Part"] -- add the missing part to rotate

local TargettingModeEnabled = false
local PausedForTweening = false

function RotateTo(part, CF, Speed)
	local tweenInfo = TweenInfo.new(Speed)
	local tween = TweenService:Create(part, tweenInfo, {CFrame = CF})

	if tween then
		PausedForTweening = true
		tween:Play()
		tween.Completed:Wait()
		PausedForTweening = false
	end
end

target:GetPropertyChangedSignal("Position"):Connect(function()
	Move(0.5, nil, workspace.Target)
	wait()
end)

function Party()
	local Color = Color3.fromHSV(math.random(150, 850) / 1000, 1, 1)
	local tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear)
	TweenService:Create(lens, tweenInfo, {Color = Color}):Play()
end

PrimaryPart:GetPropertyChangedSignal("Orientation"):Connect(function() -- pan arm movement simulation
	Pan.Orientation = Vector3.new(0, PrimaryPart.Orientation.Y + 90, 180)
	Pan.Parent.Part.Orientation = Vector3.new(0, PrimaryPart.Orientation.Y, 180)
end)

while task.wait(0.5) do
	while wait(0.5) do
		-- create the desired CFrame rotation here
		local desiredRotation = CFrame.Angles(0, math.rad(90), 0) -- Rotate 90 degrees around the Y-axis

		RotateTo(PrimaryPart, desiredRotation, 0.5)
		RotateTo(lens, desiredRotation, 0.5)
		RotateTo(Part, desiredRotation, 0.5)

		-- if Pan needs to be rotated as well, add it here
		-- RotateTo(Pan, desiredRotation, 0.5)
	end
end

Im sorry, I dont know then. I dont get what Im doing wrong.

No worries! I completely understand. Roblox CFrame (in my opinion) is a bit pointlessly over-complicated.

1 Like

Yay! Happy to help! Good luck with what you are doing! Cheers!

No worries!

Sorry, I replied to the wrong message. Meant to respond to the solution.
Nonetheless, thank you for taking the time to help. Means a lot!

Nevermind! After further review I managed to get this working. Thanks for the help!

local TweenService = game:GetService("TweenService")
local Body = script.Parent["Body"]
local PrimaryPart = Body.Head["Primary"]
local Pan = Body.Pan["BasePart"]
local target = workspace.Target

local lens = Body.Head["Lens"]

local TargettingModeEnabled = false
local PausedForTweening = false

function Move(Speed, CFrameValue, Target) -- Target only used if TargettingModeEnabled is on.
	local tweenInfo = TweenInfo.new(Speed)
	local tween
	
	if TargettingModeEnabled then
		tween = TweenService:Create(PrimaryPart, tweenInfo, {CFrame = CFrame.lookAt(PrimaryPart.Position, Target.Position)})
	else
		tween = TweenService:Create(PrimaryPart, tweenInfo, {CFrame = CFrameValue})
	end
	
	if tween then
		PausedForTweening = true
		
		tween:Play()
		tween.Completed:Wait()
		
		PausedForTweening = false
	end
end

while task.wait(0.5) do
	Move(0.5, PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90),0), nil)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.