Need help changing tool grip's orientation through a script!

Hello! I have this plushie tool that you’re able to hug for a few seconds upon clicking while holding it by changing the tool’s Grip position through a script. The hug animation looks like this right now:

ezgif-48b1fe5fc397f9

This is my script:

local Tool = script.Parent;
enabled = true

function onActivated()
	if not enabled  then
		return
	end

	enabled = false

	Tool.GripPos = Vector3.new(1.5,0,-0.5)

	wait(2)

	Tool.GripPos = Vector3.new(0,0,-0.5)

	enabled = true
end

script.Parent.Activated:connect(onActivated)

With GripPos, I managed to relatively get it into the position I wanted during and after being hugged, even though I barely understand Vector3 and just punched in numbers until it looked right.

However, I don’t know how to change the tool’s orientation through the script. I know I would have to use GripForward, GripRight and GripUp for that, and I’ve already tried them, but like I said, I don’t understand how Vector3 works and wasn’t able to get the results I wanted by just trying random numbers. Is there any easier way to do this?

Edit the tool.Grip directly and pass in a CFrame

A Vector3 is just a 3 dimensional coordinate, where the first number represents the X, the second the Y, and the third the Z. A CFrame has a few more values, but simply put, it also stores the orientation of the object.

Play around with the numbers in the following code until it looks good

Tool.Grip = CFrame.new(0, 0, 0) * CFrame.fromEulerAngles(math.rad(0), math.rad(0), math.rad(0))

The first three numbers represent the location, so probably just keep them as what you currently have in the Vector3. The 3 wrapped in “math.rad” represent the rotation on the 3 axis.

Roblox docs on CFrames if you want to actually sort of understand them

1 Like

Thanks so much, you’re awesome! It was a lot easier this way, I got it to look the way I wanted :smile:

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