local image = script.Parent.CanvasGroup.Straightline – Anchorpoint is 0.5,0.5
local heartfolder = script.Parent.CanvasGroup.Heartbeat – Just a folder
local function positioning(angle)
-- Line1
local line1 = image:Clone() -- Anchorpoint is 0.5,0.5
line1.Parent = heartfolder
line1.Rotation = angle
line1.ImageTransparency = 0
-- Center position of line1
local midX = line1.Position.X.Scale
local midY = line1.Position.Y.Scale
-- Size of line1
local halfWidth = line1.Size.X.Scale / 2
local halfHeight = line1.Size.Y.Scale / 2
-- Calculating the corner position of line1
local cornerX = midX + halfWidth
local cornerY = midY + halfHeight
local originX = cornerX - midX
local originY = cornerY - midY
-- Calculating the rotated position of the corner
local radian = math.rad(angle)
local rotatedX = originX * math.cos(radian) - originY * math.sin(radian)
local rotatedY = originX * math.sin(radian) + originY * math.cos(radian)
-- Line2
local line2 = image:Clone() -- Anchorpoint is 0.5,0.5
line2.Parent = heartfolder
line2.Name = "Line2"
line2.ImageTransparency = 0
-- Set the position of line2 at the rotated corner position
line2.Position = UDim2.new(rotatedX + halfWidth, 0, rotatedY + halfHeight, 0)
end
wait(5)
positioning(45) – Example with a 45-degree angle
– This is the script. I checked Forum and found a useful one, but still I am messing up so I used ChatGpt for the problem. But still failed please help me.
So what I understood, is that you want to keep the original point after image is rotated.
You can create variable when image is added and store the point. local point = ImageLabel.Size.X / 2 If my math head remembers corectly, this should give you rightedge. if not, then you can do local point = ImageLabel.Size.X / -2 or something like that. Also, remember to store the variable outside the fucntion, otherwise it’ll be update as the function is called
If your putting ui in that point, you can set the ui elements properties to these:
AnchorPoint = {0.5, 0}{0.5, 0}
Position = {0, 0}{0.5, 0}
Parent = x X being the main ui which is being rotated
Second option is to use code (Quite bad regarding the performance):
local frame = script.Parent
local IND = Instance.new("Frame")
IND.Size = UDim2.fromOffset(20, 20)
IND.BackgroundColor3 = Color3.new(0.78, 0, 0)
IND.AnchorPoint = Vector2.new(0.5, 0.5)
IND.Parent = frame
IND.Visible = true
local point = frame.Size.X.Scale / 2
frame:GetPropertyChangedSignal("Rotation"):Connect(function()
IND.Position = UDim2.fromScale(point, 0.5)
end)
(You get almost same result from both above)
IND is just to show position. Actually necessary part is the:
local frame = script.Parent
local point = frame.Size.X.Scale / 2
You can test this using new UIDragDetector option in studio.
Hopefully this is what you are looking for. Personal suggestion is to use 1. since it’s good regarding the performance and also if you’re duplicating the same object, the settings stay same.
As a follow up, the script which you got from ChatGPT, is full garbage. You don’t need to do fancy high school math (radians, corner calculation, etc.) to do this. Next time use deform for these kind of questions and issues.