Rotate a tool mid use with GripUp

Hi all.
I am trying to rotate a tool mid use with GripUp and it isn’t working how i want it.
So it rotates… but after you re-equip it.

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Tool = script.Parent
local h = char:WaitForChild("Humanoid")
local swing = h:LoadAnimation(script.Parent:WaitForChild("Swing"))
local swing1 = h:LoadAnimation(script.Parent:WaitForChild("Swing1"))
 
Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		local m = math.random(1,2)
		if m == 1 then
			swing:Play()
			swing:AdjustSpeed(1.5)
		elseif m == 2 then
			swing1:Play()
			swing1:AdjustSpeed(1.5)
			Tool.GripUp = Vector3.new(1,0,0)
		end
	end)
end)

result
image
desired outcome (after alternate atack)
image
but is should rotate back

When you set the GripUp property it changes it permanently until you change it again.
Try instead saving the Grip property and when some event is invoked set the tool back to the original value.

Also I suggest you use Tool.Activated because the current way you have the Tool Activation setup leads to constant memory being added for each time the tool is equipped.

Solution 1:

When the Tool is Unequipped / Equipped set the Grip back to the original Grip. A cheeky way to detect both the tool being Unequipped and Equipped is to use AncestryChanged.

Code For Solution 1
local defaultGrip = Tool.defaultGrip

Tool.Activated:Connect(function()
    local m = math.random(1, 2)

    if (m == 1) then
        --// do stuff
    elseif (m == 2) then
        --// do stuff
        Tool.GripUp = Vector3.new(1, 0, 0) --// set GripUp to new grip.
    end
end)

Tool.AncestryChanged:Connect(function() --// Watch the tool's ancestry change instead of connecting two events!
    Tool.Grip = defaultGrip --// set back to default grip
end)

Solution 2

Alternatively, you can change the Grip back to the defaultGrip after the animations have finished playing.

Code For Solution 2

Tool.Activated:Connect(function()
    local m = math.random(1, 2)

    if (m == 1) then
        --// do stuff

        swing.Stopped:Wait() --// wait for animation to finish
    elseif (m == 2) then
        --// do stuff

        Tool.GripUp = Vector3.new(1, 0, 0) --// set GripUp to new grip.
        swing2.Stopped:Wait() --// wait for animation to finish
    end

    Tool.Grip = defaultGrip
end)

No i think you misunderstood.
I want it to rotate (or snap to orientation) on atack then back.
So normal atack = no orientation change
alt atack = rotate it like he is holding a knife then back
While using.

Change the Grip property entirely during the attack then.

Tool.Grip = CFrame.new(...) --// new properties

What should i put in cframe?
I have no experience with it. sorry.

Read the API documentation.

1 Like

Oh. thx.
(30 character limit )

Someone asked a similar question;

I recommend using Animations instead.

1 Like

i thought an admin renamed my post when i got this notification

2 Likes

The GripForward, GripRight, and GripUp properties are really vector representations of the components of the tool’s Grip CFrame, so you should be changing the tool’s orientation by setting the Grip property. The 3 component vector3s will update when the grip is changes.

1 Like