Can someone fix my script?

I have a script that change player camera Position to CamPart for my main menu screen, But… When try to make the camera position back to the player, it wont go back. here is the script
– Local
local GUI = script.Parent
local MainFrame = GUI.MainFrame

local Play = MainFrame.Play

– Set up
local Cam = workspace:WaitForChild(“Camera”)
local CamPart = workspace:WaitForChild(“CamPart”)

local Players = game:GetService(“Players”)
local LocalPlayers = Players.LocalPlayer
local Char = LocalPlayers.Character or LocalPlayers.CharacterAdded:Wait()

local Lighting = game:GetService(“Lighting”)
local Blur = Lighting:WaitForChild(“Blur”)

GUI.Enabled = true

– Function
local function PLAY()
Cam.CameraType = Enum.CameraType.Custom
Cam.CFrame = Char:WaitForChild(“Humanoid”)
end

– Script
Play.Activated:Connect(PLAY)

and the 2nd script that set the player camera when they join:
– Local
local Players = game:GetService(“Players”)
local mouse = Players.LocalPlayer:GetMouse()

local CamPart = workspace:WaitForChild(“CamPart”)
local Cam = workspace:WaitForChild(“Camera”)

– Set Cam
repeat
wait()
Cam.CameraType = Enum.CameraType.Scriptable
until
Cam.CameraType == Enum.CameraType.Scriptable

-- Move
local maxTilt = 15

game:GetService(“RunService”).RenderStepped:Connect(function()
Cam.CFrame = CamPart.CFrame * CFrame.Angles(
math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
0
)
end)

anyway Thanks

1 Like

maybe when you set the camera back to the player you can do

Enum.CameraType.Custom

The issue you’re running into is that after switching to the menu camera (Scriptable), you’re trying to return the camera to the player by doing:

Cam.CameraType = Enum.CameraType.Custom
Cam.CFrame = Char:WaitForChild("Humanoid")

Cam.CFrame = Char:WaitForChild("Humanoid") is incorrect, because Humanoid is not a CFrame. You’re likely trying to reference the HumanoidRootPart.CFrame

Changes:

  1. Change Cam.CFrame = Char:WaitForChild("Humanoid")Cam.CameraSubject = Char:WaitForChild("Humanoid")

  2. Add this before setting CameraType:

if camConnection then
    camConnection:Disconnect()
    camConnection = nil
end
  1. local camConnection – Put this near the top

1 problem… Idk where to add the changes

nevermind i recode it and it work

firstly please can you use the preformatted text.

1 Like

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