I need help fixing my placing system effect

Ive made this effect but the problem is when I rotate the object the rotate effect rotates the other way please tell me how to fix this or even make it better.

Script:

local Functions = {}

Functions["MoveTween"] = function(Part, Position, Rotation)
	
	local XDifferance = Part.Position.X - Position.X
	local ZDifferance = Part.Position.Z - Position.Z
	
	print(ZDifferance)
	
	local Tween = game:GetService("TweenService")
	local Goal = {}
	Goal.CFrame = Position * CFrame.Angles(math.rad(0), math.rad(Rotation), math.rad(0))
	
	if XDifferance > 0 then
		
		Goal.CFrame = Position * CFrame.Angles(math.rad(0), math.rad(Rotation), math.rad(10))
		
	elseif XDifferance < 0 then
		
		Goal.CFrame = Position * CFrame.Angles(math.rad(0), math.rad(Rotation), math.rad(-10))
		
	end
	
	local MainTween = Tween:Create(Part, TweenInfo.new(0.1), Goal)
	MainTween:Play()
	MainTween.Completed:Wait()
	
	local BackPos = {}
	BackPos.CFrame = Position * CFrame.Angles(math.rad(0), math.rad(Rotation), math.rad(0))
	
	local BackTween = Tween:Create(Part, TweenInfo.new(0.05), BackPos)
	BackTween:Play()
	
end

No rotation:
https://gyazo.com/c1954d6ef6883b3fcfa41efac0d4499c

With rotation (Broken):
https://gyazo.com/a68bb368e37a5e15352596815847de57

use the UnitVector from item to mouse, then convert it into an angle using some trigonometry

local AngleRotation = 5 --This is in degrees
local UnitVector = (Mouse.hit.p - Part.Position).Unit

local hyp = 1 / math.cos(AngleRotation)
local opp = math.sqrt(hyp^2 - 1)

local Goal = {}
Goal.CFrame = CFrame.new(part.Position, part.Position + UnitVector - Vector3.new(0,opp,0))

You can get rid of your if xDifference checks then, I’m a bit rusty at trigonometry so it might not be right, worth a shot though.

1 Like

Thank you but on line 2 of your code
local UnitVector = (Mouse.hit.p, Part.Position).Unit
it has an error saying Expected ')' (to close '(' at column 21), got ','

My bad, i meant to write

local UnitVector = (Mouse.hit.p - Part.Position).Unit
1 Like

Sadly, it doesn’t work but AngleRotation isn’t used anywhere. Thank you for trying though.

It should work, AngleRotation is how much you want the part to rotate by when it moves
i can make a pseudo-code version of it so you can fill it out yourself if you like

Wait i’ve edited my code, try it again

Yes please. :smiley: Just filling it bc of the character limit

local HowMuchYouWantItToRotate = 5 --This is in degrees
local UnitVector = (Goal - StartingPoint).Unit

local hyp = 1 / math.cos(HowMuchYouWantItToRotate)
local opp = math.sqrt(hyp^2 - 1)

local Goal = {}
Goal.CFrame = CFrame.new(StartingPoint, StartingPoint + UnitVector - Vector3.new(0,opp,0))

Just change the ‘StartingPoint’ and ‘Goal’ and it should work

1 Like

The variable

HowMuchYouWantItToRotate
isn’t used in the script except when you make the variable

Ohh yes you are right, i am so sorry im a bit tired and not paying attention, let me change it one last time

EDIT: There you are, it should be fine now, sorry again

1 Like

it goes into the ground lol :smiley:image

Rip still doesnt work thank you so much for trying :smiley: