Camera Manipulation Error

Hello.

I’ve come across an issue. I’m trying to create a menu screen, but the camera refuses to lock itself back onto the player’s character after it’s respawned. The menu screen itself works fine; it’s just that the camera will get stuck if I reset my character.

To fix this, I’ve already tried toggling ResetOnSpawn, deleting the camera part that the camera is fixed on, deleting any scripts that have to do with changing the camera’s position, but nothing seems to prevent or fix the error that I’m having.

The following code is run when I press the play button.

camera.CameraSubject = character:FindFirstChild("Humanoid")
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = character:FindFirstChild("Head").CFrame

button:TweenPosition(UDim2.new(100, 0, 100, 0))

StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)

for _, v in pairs(character:GetDescendants()) do
	if v:IsA("BasePart") or v:IsA("Decal") then
		if v.Name ~= "HumanoidRootPart" then
			v.Transparency = 0
		end
	end
end
	
cameraPart:Destroy()
button.Parent.Parent.Script:Destroy()
script:Destroy()

The following screenshot displays my system’s layout.

image

Does anyone have a solution to this? Thank you.

It doesn’t seem like you are resetting the camera subject to the character anywhere so it’s just staying focused on the HRP.

The very first line of the code that I shared changes the camera’s CameraSubject. I tried changing it to simply be the character, but the camera still gets stuck if I reset my character.

What kind of camera are you using? Is it the one from workspace?

Yes. It’s the CurrentCamera.


local player = game.Players.LocalPlayer
local started = false
--When the button is pressed, the "started" boolean should be set to true, that way, the character event can't immediately start when you spawn into the game, but rather have the button pressed first.

player.CharacterAdded:Connect(function(character)
    if started == false then return end
    camera.CameraSubject = character:FindFirstChild("Humanoid")
    camera.CameraType = Enum.CameraType.Custom
    camera.CFrame = character:FindFirstChild("Head").CFrame

    button:TweenPosition(UDim2.new(100, 0, 100, 0))

    StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)

    for _, v in pairs(character:GetDescendants()) do
	    if v:IsA("BasePart") or v:IsA("Decal") then
		    if v.Name ~= "HumanoidRootPart" then
			    v.Transparency = 0
		    end
	    end
    end
end)

Try this out. I think it needs a signal that the character of the player has respawned and get a new character. The current character’s head that the camera was targeting on still shows nothing even if the head was destroyed. Putting this event out there, however, will refresh the camera’s target to a new, respawned character.

Perhaps have the code into the CharacterAdded() and have another when you press the UI button, or better yet, create a function that handles the camera code, and put it into both scenarios.

I would just suggest removing reset while on the menu. In my opinion, it’s better not being able to reset in the menu screen.

(If you insist on have a reset option, you could fire the client when they die and reset the camera’s position.)

Disregard. Thank you to all who attempted to assist me.

I’ve located the issue. I had to place the local script in which I set the camera’s position inside of the ScreenGui, else it would keep looping every time I reset my character.

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