So I made a very very basic menu script where when the player loads in their camera is not at the player but at a specific location which that works. But when I try to make it rotate it just doesn’t want to do it.
I as well I’m trying to learn many different things so CFrames is a bit of a new concept.
Here is the script for my menu:
local playerService = game:GetService("Players")
local playerGui = playerService.LocalPlayer:WaitForChild("PlayerGui")
local mainMenu = playerGui:FindFirstChild("MainMenu")
local getCamera = game.Workspace.CurrentCamera
local menu = script.Parent
local frame = menu.Frame
local cameraRotateSpeed = 10
task.wait(0.1)
getCamera.CameraType = Enum.CameraType.Scriptable
while true do
getCamera.CFrame = CFrame.new(100, 100, 100) * CFrame.Angles(45 * cameraRotateSpeed , 0, 0)
end
local function onPlayClick()
local getFrame = mainMenu:FindFirstChild("Frame")
getFrame.Visible = not getFrame.Visible
getCamera.CameraType = Enum.CameraType.Custom
print("The code got past this point")
end
frame.TextButton.MouseButton1Click:Connect(onPlayClick)
If someone could explain to me how I could make my camera rotate and on how to do it would be helpful.
And as well to mention when I press the Play GUI the camera does return to the player but I want the scriptable camera to rotate at the CFrame it is located at.
you running an infinite loop try use task.spawn and but the the while loop in it or down of your script
do something like this don’t forget to add task.wait() or your studio will crash
local playerService = game:GetService("Players")
local playerGui = playerService.LocalPlayer:WaitForChild("PlayerGui")
local mainMenu = playerGui:FindFirstChild("MainMenu")
local getCamera = game.Workspace.CurrentCamera
local menu = script.Parent
local frame = menu.Frame
local cameraRotateSpeed = 10
task.wait(0.1)
getCamera.CameraType = Enum.CameraType.Scriptable
local function onPlayClick()
local getFrame = mainMenu:FindFirstChild("Frame")
getFrame.Visible = not getFrame.Visible
getCamera.CameraType = Enum.CameraType.Custom
print("The code got past this point")
end
frame.TextButton.MouseButton1Click:Connect(onPlayClick)
task.spawn(function()
while true do
task.wait()
getCamera.CFrame = CFrame.new(100, 100, 100) * CFrame.Angles(45 * cameraRotateSpeed , 0, 0)
end
end)
there are a lot going wrong here such as setting the while loop before the code ends since its a endless while loop the code never reaches the connect and not forgetting how your studio can handle while true do you should always have wait() or else have cpu for dinner also you forgot to convert the numbers to math.rad()
so getcamera.cframe = cframe.new(…) * cframe.angles(math.rad(…) * math.rad(…), 0, 0)