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)
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
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.