Play button not forcing camera back to the player

hello, I am trying to force the camera back to the player (the camera is being cframed and such). However i tried to set the camera back to the player, but instead it just stayed where it was at. So far what i have tried to do is setting the camera type, camera subject, and even setting an empty cframe, although to no avail. Here is my code:

-- Variables

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Camera = workspace.CurrentCamera
local Mouse = game.Players.LocalPlayer:GetMouse()
local DefaultCFrame = workspace.StartMenuScreen.camerapart.CFrame
local USI = game:GetService("UserInputService")
local popsound = workspace.StartMenuScreen.pop
local Scale = 500
local gui = script.Parent
local blur = game.Lighting.Blur
local Background = script.Parent.background
local PlayButton = Background.play
local HelpButton = Background.help 
local SettingsButton = Background.settings 
local DonateButton = Background.donate
local TweenService = game:GetService("TweenService")
local PlayerRain = game.Players.LocalPlayer.PlayerScripts.weather
local isRainDisabled = true
local HumanoidInst = Character:WaitForChild("Humanoid")

hasplayerclickedplay = false


gui.Enabled = true
blur.Enabled = true



repeat wait() -- - We made the loop so the camera will be set to the Scriptable property.
	Camera.CameraType = Enum.CameraType.Scriptable -- The line of code in which we tell the game that we need the camera to be set to the Scriptable property.
until Camera.CameraType == Enum.CameraType.Scriptable -- And this line is telling the game that if the Camera is set to the Scriptable property, then the loop ends.

game:GetService("RunService").RenderStepped:Connect(function() -- Getting the service known as "RunService"
	if hasplayerclickedplay == false then
		Camera.Focus = DefaultCFrame
		local Center = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
		local MoveVector = Vector3.new((Mouse.X-Center.X)/Scale, -(Mouse.Y-Center.Y)/Scale, 0)
		Camera.CFrame = DefaultCFrame * CFrame.Angles(math.rad(MoveVector.X), math.rad(MoveVector.Y), math.rad(MoveVector.Z))
		Camera.FieldOfView = 100 -- Setting the FieldOfView, you're free to customize this however you want to
	end
end) 

Camera.CFrame = workspace.StartMenuScreen.camerapart.CFrame -- This is where your camera is, and the "CameraPart" is what my part is called.

if isRainDisabled == true then
	PlayerRain.Disabled = true
else
	--Do Nothing.
end



----------------------------------------------------------------------------------------------------------------------------------------------------

local function Hover(HoverEffect)
	local originalPosition = HoverEffect.Position
	HoverEffect.MouseEnter:Connect(function()
		popsound:Play()
	end)
	HoverEffect.MouseLeave:Connect(function()
		--nothing to do here
	end)
end



Hover(PlayButton)
Hover(HelpButton)
Hover(SettingsButton)
Hover(DonateButton)

PlayButton.Activated:Connect(function()
	blur.Enabled = false
	gui.Enabled = false
	hasplayerclickedplay = true
	Camera.CameraSubject = HumanoidInst
	Camera.CameraType = Enum.CameraType.Fixed
end)

Try adding in print statement s after each major section, and maybe that can help you see if and where any errors are.

1 Like

well i have no errors, and also everything changes like its supposed to. It changes from scriptable to fixed and the subject is set to the humanoid, but it doesnt go back to the player like normal.

I’m not very experienced in CFrames, so I can’t help much here, but I would suggest turning on the break on unhandled errors, if you haven’t already. Other than that, I can’t say much more than good luck. :confused:

Change the CameraType to custom instead of fixed.

1 Like

thank you so much, you are a life saver!

No problems, glad I helped :smile:

2 Likes