I need help with a rotation script

I made a script that makes it so if you type ‘Q’ it rotates the camera by 90 degrees. But when I double tap Q it turns it twice so therefore it turns 90 degrees twice, turning itself around(Which I don’t want)

Here’s my script:

local ts = game:GetService("TweenService")
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera

local part = workspace:WaitForChild("Campart")

camera.CameraType = Enum.CameraType.Scriptable


cameraCFrame = part.CFrame

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		camera.CameraType = Enum.CameraType.Scriptable
		local Tweeninfo = TweenInfo.new(0.5) --time of tween

		ts:Create(camera,Tweeninfo,{CFrame = CFrame.new(0,90,0)}):Play()
	end
	uis.InputEnded:Connect(function(input)
		if input.KeyCode == Enum.KeyCode.Q then
			--[[ 
               local Tweeninfo = TweenInfo.new(0.5) --time of tween
			   ts:Create(camera,Tweeninfo,{CFrame = part.CFrame}):Play()
			--]]
		
		    end
        end)
	end)


Try changing to:

local ts = game:GetService("TweenService")
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera

local part = workspace:WaitForChild("Campart")

camera.CameraType = Enum.CameraType.Scriptable


cameraCFrame = part.CFrame

local inTransition = false
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q and not inTransition then
        inTransition = true
		camera.CameraType = Enum.CameraType.Scriptable
		local Tweeninfo = TweenInfo.new(0.5) --time of tween
		ts:Create(camera,Tweeninfo,{CFrame = CFrame.new(0,90,0)}):Play()
	end
end)
uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q and inTransition then
        inTransition = false
        local Tweeninfo = TweenInfo.new(0.5) --time of tween
		ts:Create(camera,Tweeninfo,{CFrame = part.CFrame}):Play()
		
    end
end)

Now the camera just launches upward

nvm I fixed it, but now it is doing the same thing again

You’re probably looking for CFrame.angles() instead of CFrame.new(), replace

ts:Create(camera,Tweeninfo,{CFrame = CFrame.new(0,90,0)}):Play()

with

ts:Create(camera,Tweeninfo,{
    CFrame = camera.CFrame * CFrame.angles(0,math.rad(90),0)
}):Play()

Its giving me this error:

I think its because you didn’t capitalize angles? idk

its also doing the same thing

Ahhh yes sorry, capital A for CFrame.Angles()

yeah but its still doing the same thing

Can you tell me what the code is on line 19??

the use of a debounce is what you need but only reset the debounce after the tween finishes not on input ended
the rotational part of the camera cframe may need fixed in your script but here is how you use the debounce correctly

local ts = game:GetService("TweenService")
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local debounce  -- used to keep from doubling until tween is done


local part = workspace:WaitForChild("Campart")

camera.CameraType = Enum.CameraType.Scriptable


cameraCFrame = part.CFrame

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q and not debounce then
		debounce = true  -- set so it doesn't run again 
		camera.CameraType = Enum.CameraType.Scriptable
		local Tweeninfo = TweenInfo.new(0.5) --time of tween

		local Tween = ts:Create(camera,Tweeninfo,{CFrame = CFrame.new(0,90,0)})
		Tween:Play()
		Tween.Completed:Wait() -- wait until camera tween finishes
		print('finished')
		debounce = nil  -- remove the debounce
	end
end)


uis.InputEnded:Connect(function(input)  -- this needs to be outside of inputbegin else it will make multi connections
	if input.KeyCode == Enum.KeyCode.Q then
			--[[ 
               local Tweeninfo = TweenInfo.new(0.5) --time of tween
			   ts:Create(camera,Tweeninfo,{CFrame = part.CFrame}):Play()
			--]]

	end
end)

Thank you for your time! I finally got this working!

1 Like

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