Recently, I made a script that does something whenever the DragDetector’s DragFrame position is greater than a number. Now I want the DragFrame.Position to change when I press a button. I have tried doing DragFrame.Position = Vector3.new(...)
but it throws me the “position cannot be assigned to” error. I have heard that because position is read-only I have to change the whole DragFrame, but I don’t know how to do that and failed all my tries. Any help is appreciated!
DragFrame
is a CFrame, and you cannot change the properties of CFrames, including Position
.
Instead, create a new CFrame using CFrame.new()
and put the xyz axes of your desired position.
DragDetector.DragFrame = CFrame.new(x, y, z)
Yes you do need to set DragFrame from DragDetector directly instead of using a variable
Okay, that kinda worked. However the rotation resets to 0, 0, 0 when I need it to be -85, 0, 0. How can I implement rotation in there?
You have three options:
A. When you want the rotation to always be (-85, 0, 0)
DragDetector.DragFrame = CFrame.new(x, y, z) * CFrame.Angles(math.rad(-85), 0, 0)
B. When you want the rotation to be changeable while moving the DragFrame using ToEulerAnglesXYZ() (meaning the rotation is not always (-85, 0, 0))
local rx, ry, rz = DragDetector.DragFrame:ToEulerAnglesXYZ()
DragDetector.DragFrame = CFrame.new(x, y, z) * CFrame.Angles(rx, ry, rz)
C. When you want the rotation to be changeable while moving the DragFrame using rotation matrix.
DragDetector.DragFrame = CFrame.fromMatrix(Vector3.new(x, y, z), DragDetector.DragFrame.XVector, DragDetector.DragFrame.YVector, DragDetector.DragFrame.ZVector)
Thank you so much, one last thing. I have set the CFrame.new(x, y, z) to a fixed value but it doesn’t move it to the actual position that I want every time. For example when I leave the drag detector on the x axis +2 from the x,y,z position, instead of moving to that exact point, it moves like -2 on the x axis from that position. However if I look the DragFrame position it’s the same, even though the actual parts are 2 studs away from the DragFrame position I want.
Example:
Starting position (and the position I want it to go when I click the brick):
Position I left the DragDetector:
Position it goes to after pressing the button:
As you can see the DragFrame position is exactly the same, but the actual position differs. Only when I move it just a bit it goes back inside the limits.
Sorry, I’m not that familiar with DragDetectors yet. They’re new and in beta, so expect some bugs.
Hopefully, someone can help you with that. Now that my business is done here, bye!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.