Why does this script not work? I read a bit and saw that I need to apply it to a CFrame instead of position!

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local part = game.Workspace:WaitForChild("House1")
local primPart = part:WaitForChild("HitBox")
local Posi = part:GetPivot()
local tweenService = game:GetService("TweenService")

local primPos = primPart.CFrame.Position

local UIS = game:GetService("UserInputService")

local EV = game.ReplicatedStorage.Placing

local Xup = nil
local Zup = nil

local y = Posi.Y

local canPlace = false

local ValuePos = Instance.new("Vector3Value")
ValuePos.Parent = game.Workspace

local function Move()
	wait(0.25)
	
	
	local x,z = mouse.Hit.X, mouse.Hit.Z
	
	Xup = math.floor(x / 4 + 0.5) * 4
	Zup = math.floor(z / 4 + 0.5) * 4

	local tweenInfo = TweenInfo.new(
		0.25,
		Enum.EasingStyle.Back,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tweenPart = tweenService:Create(ValuePos, tweenInfo, {Value = Vector3.new(Xup,y,Zup)})
	
	tweenPart:Play()
	
	
	
	local filter = OverlapParams.new()
	filter.FilterType = Enum.RaycastFilterType.Exclude
	filter.FilterDescendantsInstances = {game.Workspace.Baseplate, player.Character, part}

	local foundParts = workspace:GetPartsInPart(part.HitBox, filter)
	
	if foundParts[1] ~= nil then
		part.Highlight.FillColor = Color3.new(255,0,0)
		canPlace = false
	else

		part.Highlight.FillColor = Color3.new(0,255,0)
		canPlace = true
	end
	
end

ValuePos:GetPropertyChangedSignal("Value"):Connect(function()
	primPart.Position = ValuePos.Value
end)

local function Rotate(input)
	if input.KeyCode == Enum.KeyCode.R then
		local OriX,OriY,OriZ = primPart.Orientation.X, primPart.Orientation.Y, primPart.Orientation.Z
		print(OriX,OriY,OriZ)
		
		primPart.Orientation = Vector3.new(OriX,OriY+90,OriZ)
	end	
end

mouse.Move:Connect(Move)

This is the script I have so far. I am having trouble with this

local tweenPart = tweenService:Create(ValuePos, tweenInfo, {Value = Vector3.new(Xup,y,Zup)})
	
	tweenPart:Play()

And

ValuePos:GetPropertyChangedSignal("Value"):Connect(function()
	primPart.Position = ValuePos.Value
end)

I have welded everything together properly but it does not seem to work. The primary part moves but nothing else does. I saw a devforum post and it said that it will not move during tweening unless you use CFrame which does not work in my situation!

HELP!

Why can’t u use cframe for this?

You can turn the parts into one single mesh by right clicking the selected parts and then clicking “Export Selection…” After that, select the file you want the mesh to be located at (For instance, clicking “Downloads”, naming your file by your name of choice, and finally clicking “Save” will put your mesh file into “Downloads”, which means that when you open your files and go to the “Downloads” tab, your mesh file will be found there.)

After that, your problem will hopefully be solved.

It looks like you’re tweening a Vector3 value, to then update a part’s position to that value.

Aren’t you just able to tween the part position itself?

The reason I am doing this is because unless you use CFrame the weld constraints will not update and only the primary part will work. I cannot use CFrame because it messes up the rotation part of the script.

Just create a CFrameValue with no parent, so it stays hidden but useable, then do something like this:

local part = workspace.Part

local cframe = Instance.new("CFrameValue")

part.CFrame = cframe.Value

cframe:GetPropertyChangedSignal("Value"):Connect(function()
    part.CFrame = cframe.Value
end)

Changing the CFrame value will change the Part’s CFrame.


Also, if you’re trying to move a model, use :PivotTo() instead, as it moves all the parts, not just one.

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