Rotation tween only working if not rotated in the Y or Z axis

In my game I’m trying to make a realistic revolver animation. When the trigger is pulled, the hammer should go back, and then return really quickly to fire the round. And this indeed happens with my current script.
robloxapp-20240319-1940437

But if the gun isn’t lined up with the X axis (it’s rotated in the Y and or Z axis) then this happens.

robloxapp-20240319-1949471

The hammer still rotates 60 degrees in the X axis, but I need it to rotate BACK which happens to be in the X axis when it’s not rotated in the Y or Z axis (if you understand what I mean).
Here is my script:

local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local TweenService = game:GetService("TweenService")
local hammer = character.Hammer

function Fire()
	local OriginalRotation = hammer.Rotation
	local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Cubic, Enum.EasingDirection.In)
	local tween = TweenService:Create(hammer, tweenInfo, {Rotation = hammer.Rotation + Vector3.new(-60, 0, 0)})
	tween:Play()
	wait(0.5)
	local tweenInfo1 = TweenInfo.new(0.0025, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
	local tween1 = TweenService:Create(hammer, tweenInfo, {Rotation = hammer.Rotation - Vector3.new(-60, 0, 0)})
	tween1:Play()
	--wait(0.25)
	tween1.Completed:Wait()
	local animation = Instance.new("Animation")
	animation.AnimationId = "http://www.roblox.com/asset/?id=16799062288"
	local animationTrack = humanoid:LoadAnimation(animation)
	animationTrack:Play()
end

wait(5)
Fire()

There is probably a simple solution for this but I’m all out of ideas. I appreciate any help I get though.

I don’t have an exact solution, but the issue seems to stem from the fact that you don’t use any formula to set the rotation depending on the tool’s rotation, rather you only account for the tool having its y and z value equal to zero so that it can tween the x rotation of that part of the tool to -60.

If i understanded you right, you are wanting to make the revolver animated right?
if you do so, you need to use motor6d (better than using tweenservice)

1 Like

Yeah I’m a fool, probably could’ve done this by myself. Thanks for the help though.

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