How Would I Add Rotation To my Lock Pick system?

How Would I Go By Making My Lock System Go Left And Right, Example https://www.youtube.com/watch?v=mx8sibfnu8k

I Know it has to do with UserInputService, By How Should I do it With, TweenService Or Lerp Or WeldConstant Or Motor6D

First Solution(I Tried)

UserInputService.InputBegan:Connect(function(input, isProcessed)
	if isProcessed then return end
	if input.KeyCode == Enum.KeyCode.Left then
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = LockObject.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(-MaxRotation))}):Play()
	elseif input.KeyCode == Enum.KeyCode.Right then
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = LockObject.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(MaxRotation))}):Play()
	end
end)

UserInputService.InputEnded:Connect(function(input, isProcessed)
	if isProcessed then return end
	if input.KeyCode == Enum.KeyCode.Left then
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = LockLocation}):Play()
	elseif input.KeyCode == Enum.KeyCode.Right then
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = LockLocation}):Play()
	end
end)

And what was the result of that solution you tried?

The Only Problem Is that I Can Spam it and it would go out of rotation

Either you should check if it could rotate further or add a debounce

How Would I go By checking if it can rotate further?

If the default rotation is 0, 0, 0 then you’d just check if it’s at 0, 0, 60, if so you’d just not rotate it. Exactly the same for the other rotation but just -60

(That may not work since you’re tweening it)
When it’s first initialized you could you could just calculate the rotation and just tween it to there after

-- You should find a way to calculate it when picklocking starts
local lRot = LockObject.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(-MaxRotation))
local rRot = LockObject.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(MaxRotation))

UserInputService.InputBegan:Connect(function(input, isProcessed)
	if isProcessed then return end
	if input.KeyCode == Enum.KeyCode.Left then
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = lRot}):Play()
	elseif input.KeyCode == Enum.KeyCode.Right then
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = rRot}):Play()
	end
end)

UserInputService.InputEnded:Connect(function(input, isProcessed)
	if isProcessed then return end
	if input.KeyCode == Enum.KeyCode.Left then
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = LockLocation}):Play()
	elseif input.KeyCode == Enum.KeyCode.Right then
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = LockLocation}):Play()
	end
end)

And just tween it to there in the actual input detection function

This is Almost it, But how do you think i can go by making if Left Is getting Pressed and You tried to press Right it cant Rotation!

local MaxRotation = 60
local LockLocation = LockObject.PrimaryPart.CFrame
local prevKey, isRotating = nil, false

local lRot = LockObject.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(-MaxRotation))
local rRot = LockObject.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(MaxRotation))

UserInputService.InputBegan:Connect(function(input, isProcessed)
	if isProcessed or isRotating then return end
	if input.KeyCode == Enum.KeyCode.Left then
		prevKey = "left"
		isRotating = true
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = lRot}):Play()
	elseif input.KeyCode == Enum.KeyCode.Right then
		prevKey = "right"
		isRotating = true
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = rRot}):Play()
	end
end)

UserInputService.InputEnded:Connect(function(input, isProcessed)
	if isProcessed or not isRotating then return end
	if input.KeyCode == Enum.KeyCode.Left and prevKey == "left" then
		isRotating = false
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = LockLocation}):Play()
	elseif input.KeyCode == Enum.KeyCode.Right and prevKey == "right" then
		isRotating = false
		TweenService:Create(LockObject.PrimaryPart, TweenInfo.new(.5), {CFrame = LockLocation}):Play()
	end
end)

This should work. For some reason if you don’t check previous key then if you press another key down it registers the other key as InputEnded, but i got past that.
Let me know if this works or not.

Oh my god, Life Saver Yeah it worked perfectly

All I Am Missing Is The Pin Part, But I’m try to see if i can figure it out

appreciate It

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