Camera is soft locked after setting to `Custom`

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A moveable camera with right click.

  2. What is the issue? Include screenshots / videos if possible!
    Watch 2024-07-21 15-45-18 | Streamable

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Researched on the dev forums and Google.

I have a model for setting the camera’s position easily for the main menu, it’s supposed to set the camera to the player itself after pressing “Play”.

script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	humanoidRootPart.Anchored = false
	
	if not character or not character:FindFirstChild("Humanoid") then
		print("Character or Humanoid not found")
		return
	end

	local currentCamera = game.Workspace.CurrentCamera
	if not currentCamera then
		print("CurrentCamera not found")
		return
	end

	-- camera follows the humanoid (should work?)
	currentCamera.CameraType = Enum.CameraType.Custom
	currentCamera.CameraSubject = character:FindFirstChildOfClass("Humanoid")

	local head = character:FindFirstChild("Head")
	if head then
		local cameraOffset = Vector3.new(0, 5, -10)
		currentCamera.CFrame = CFrame.new(head.Position + cameraOffset, head.Position)
	else
		print("Head not found in the character")
	end

	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart then
		print(player.Name .. " (" .. tostring(humanoidRootPart.CFrame) .. ")")
	else
		print("HumanoidRootPart not found for " .. player.Name)
	end
end)

can you send the script for the main menu camera?

pcall(function()
	local player = game.Players.LocalPlayer
	local char = player.Character or player.CharacterAdded:Wait()
	local cam = workspace.CurrentCamera
	local com = workspace.cammod.com
	
	repeat task.wait()
		cam.CameraType = Enum.CameraType.Scriptable
	until 
		cam.CameraType == Enum.CameraType.Scriptable
	
	while script.Parent.Parent do
		task.wait();
		cam.CFrame = com.CFrame
	end
end)

If this code is horrible, sorry, I’ve never used camera’s

sorry but can can you send the entire script? and also for the play button code? i just like having some more context :sweat_smile:

Sure here’s all my main menu related (local) scripts.

-- StarterGui
pcall(function()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local com = workspace.cammod.com

repeat task.wait()
	cam.CameraType = Enum.CameraType.Scriptable
until 
	cam.CameraType == Enum.CameraType.Scriptable

while script.Parent.Parent do
	task.wait();
	cam.CFrame = com.CFrame
end
end)

-- Under the Play button in my GUI
script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	humanoidRootPart.Anchored = false
	
	if not character or not character:FindFirstChild("Humanoid") then
		print("Character or Humanoid not found")
		return
	end

	local currentCamera = game.Workspace.CurrentCamera
	if not currentCamera then
		print("CurrentCamera not found")
		return
	end

	-- camera follows the humanoid (should work?)
	currentCamera.CameraType = Enum.CameraType.Custom
	currentCamera.CameraSubject = character:FindFirstChildOfClass("Humanoid")

	local head = character:FindFirstChild("Head")
	if head then
		local cameraOffset = Vector3.new(0, 5, -10)
		currentCamera.CFrame = CFrame.new(head.Position + cameraOffset, head.Position)
	else
		print("Head not found in the character")
	end

	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart then
		print(player.Name .. " (" .. tostring(humanoidRootPart.CFrame) .. ")")
	else
		print("HumanoidRootPart not found for " .. player.Name)
	end
end)

-- Local script which has the GUI's as children (ReplicatedFirst)
-- Remove default loading screen
game.ReplicatedFirst:RemoveDefaultLoadingScreen()

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local Load = script:FindFirstChild("Load")
local Frame = Load:FindFirstChild("Frame")


Load.Parent = player.PlayerGui


local function Debris(item, lifetime)
	game:GetService("Debris"):AddItem(item, lifetime)
end

-- await for the game to load
repeat wait() until game:IsLoaded()

local TweenService = game:GetService("TweenService")

local TransparencyInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Quint,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local TransparencyTween = TweenService:Create(Frame, TransparencyInfo, {Transparency = 1})
task.wait(2)
TransparencyTween:Play()
Debris(Load, 1) -- adds to queue
task.wait(1)

local WelcomeGui = script.Welcome
WelcomeGui.Parent = player.PlayerGui

local PlayButton = WelcomeGui:FindFirstChild("Play")
local SettingsButton = WelcomeGui:FindFirstChild("Settings")

local FirstThing = WelcomeGui:FindFirstChild("First")
local SecondThing = WelcomeGui:FindFirstChild("Second")

PlayButton:TweenPosition(UDim2.new(0.032, 0, 0.876, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, false)
FirstThing:TweenPosition(UDim2.new(0.02, 0, 0.88, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, false)
task.wait(0.25)
SettingsButton:TweenPosition(UDim2.new(0.032, 0, 0.915, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, false)
SecondThing:TweenPosition(UDim2.new(0.02, 0, 0.917, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, false)
task.wait(1)

PlayButton.MouseEnter:Connect(function()
	FirstThing.Visible = true
end)

SettingsButton.MouseEnter:Connect(function()
	SecondThing.Visible = true
end)

PlayButton.MouseLeave:Connect(function()
	FirstThing.Visible = false
end)

SettingsButton.MouseLeave:Connect(function()
	SecondThing.Visible = false
end)

Photo’s for context:
image
image

Sorry for the reply taking a bit I just want it to make sense.

Firstly, you want to add a bool value inside the welcome gui named “inMenu”, and make sure it is set to TRUE. Like this:

Second, you want to change the while do loop to a repeat until loop, and make it repeat until the value is turned to false like this:

pcall(function()
	local player = game.Players.LocalPlayer
	local char = player.Character or player.CharacterAdded:Wait()
	local cam = workspace.CurrentCamera
	local com = workspace.cammod.com
	local inMenu = player.PlayerGui:WaitForChild("Welcome").inMenu

	repeat task.wait()
		cam.CameraType = Enum.CameraType.Scriptable
	until 
	cam.CameraType == Enum.CameraType.Scriptable

	repeat task.wait()
		task.wait()
		cam.CFrame = com.CFrame
	until inMenu.Value == false
end)

Lastly, inside the play button script you want to set the value to false, which will then end the repeat loop! It is the first thing we change so that the loop doesnt run any extra times which would make the transition choppy. Like this:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.inMenu.Value = false -- right here is what I changed!
	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	humanoidRootPart.Anchored = false

If there are any issuse please let me know

1 Like

Thank you so much!

It works perfectly now, I didn’t really think about using a boolValue to check if the GUI was open, haha.

1 Like

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