Tweening from main manu camera to the player one

Hello, I am trying to achieve a Camera main menu that you can slightly move with the mouse, but this is not the problem. The problem is that I don t know how to tween it from the Main Menu one to the player’s.

I keep getting sorts of errors like:

StarterPlayerScripts is not a valid member of DataModel
TweenService:Create no property named ‘ (Camera)’ for object ‘Camera’ - Client - CameraMenu:40

I think that I am trying to Tween it wrong, I tried some weird ideas that came to mind, I searched on Devforum but there wasn’t really anything that helped too much so I decided to create a topic even if I don’t really like asking for so much help.

local player = game:GetService("Players").LocalPlayer
local cam = workspace.CurrentCamera
local camPart = workspace.PlayCam
local mouse = player:GetMouse()
local isPlaying = false
local originalCameraType = Enum.CameraType.Custom
local originalCameraCFrame = cam.CFrame
local debounce = false

cam.CameraType = Enum.CameraType.Scriptable

local maxTilt = 10


local function updateCamera()
	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

local function setPlayerCamera()
	cam.CameraType = originalCameraType
	cam.CFrame = originalCameraCFrame
end

local playButton = script.Parent.Frame.PlayButton

local function onPlayButtonClicked()
	if debounce == false then
		debounce = false -- Ignore the debouce, I just tested something
		isPlaying = not isPlaying
		if isPlaying then
			setPlayerCamera()
		else
			cam.CameraType = Enum.CameraType.Scriptable
		end
	else
		return
	end
end

playButton.MouseButton1Click:Connect(onPlayButtonClicked)

game:GetService("RunService").RenderStepped:Connect(function()
	if not isPlaying then
		updateCamera()
	end
end)

Please don’t put to much effort in this topic!

1 Like

Is this the correct script you need fixing? Because I don’t see StarterPlayerScripts nor TweenService being required.

This is the script without the tween, because it was way to messy and it didn t even work at all. The errors were from the ones with the tweens tho.

this is what i tried with the tween:

local player = game:GetService("Players").LocalPlayer
local cam = workspace.CurrentCamera
local camPart = workspace.PlayCam
local mouse = player:GetMouse()
local isPlaying = false
local originalCameraType = Enum.CameraType.Custom
local originalCameraCFrame = cam.CFrame
local debounce = false

local TweenService = game:GetService("TweenService")


cam.CameraType = Enum.CameraType.Scriptable

--// Move cam
local maxTilt = 10


local function updateCamera()
	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


local function transitionToPlayerCamera()
	local playerCharacter = player.Character
	if playerCharacter then
		local playerCameraSubject = playerCharacter.Humanoid
		cam.CameraType = Enum.CameraType.Custom
		
	
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
		local tweenGoal = {}
		tweenGoal.CameraSubject = playerCameraSubject

		local cameraTween = TweenService:Create(cam, tweenInfo, tweenGoal)
		cameraTween:Play()
	end
end


local playButton = script.Parent.Frame.PlayButton


local function onPlayButtonClicked()
	if debounce == false then
		debounce = true
		isPlaying = not isPlaying
		if isPlaying then
			transitionToPlayerCamera()
		else
			
			local playerCameraSubject = player.Character:FindFirstChild("Humanoid")
			cam.CameraType = Enum.CameraType.Custom
			
			local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
			local tweenGoal = {}
			tweenGoal.CameraSubject = playerCameraSubject

			local cameraTween = TweenService:Create(cam, tweenInfo, tweenGoal)
			cameraTween:Play()
		end
		wait(1) 
		debounce = false
	end
end


playButton.MouseButton1Click:Connect(onPlayButtonClicked)

game:GetService("RunService").RenderStepped:Connect(function()
	if not isPlaying then
		updateCamera()
	end
end)

TweenGoal is an array with no keys defined, therefore the goal tween is nil.

Consequently, that causes the second error. It also seems that you tried setting a value in the tweenGoal array but also forgot to define the cframe.

--example
local tween = game.GetService:("TweenService"):Create(workspace.PointA.CFrame, TweenInfo.new(1, Enum.EasingStyle.Linear), {["CFrame"] = workspace.PointB.CFrame})

To fix your original predicament, you basically forgot to make a goal to tween to.

--sorry for semi-late reply lolololol
local function transitionToPlayerCamera()
	local playerCharacter = player.Character
	if playerCharacter then
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
		local cameraTween = TweenService:Create(cam, tweenInfo, {["CFrame"] = playerCameraSubject.CFrame}) --easier to just create an array with the cframe within
		cameraTween:Play()
		cam.CameraType = Enum.CameraType.Custom
	end
end

1 Like

Thanks for the help! I replaced the old function, but the tween still isn’t happening. The camera just teleports to the player. But i seem to have another error:
CFrame is not a valid member of Humanoid “Workspace.playername.Humanoid” - Client - CameraMenu:33

line 33 being:

local cameraTween = TweenService:Create(cam, tweenInfo, {[“CFrame”] = playerCameraSubject.CFrame})

The help was appreciated tho!

Ah, I realized I made a mistake with playerCameraSubject, replace that with originalCameraCFrame

1 Like

Thanks! it s working now but the tween starts from behind the player and not from the campart.

Replace “cam” with “camPart.CFrame” in the TweenService:Create

local cameraTween = TweenService:Create(camPart.CFrame, tweenInfo, {["CFrame"] = playerCameraSubject.CFrame})
1 Like

I replaced them but now I get the error:
14:39:47.948 Players.playername.PlayerGui.ScreenGui.CameraMenu:33: attempt to index nil with ‘CFrame’ - Client - CameraMenu:33
14:39:47.948 CFrame is not a valid member of Humanoid “Workspace.playername.Humanoid” - Client - CameraMenu:30

local function transitionToPlayerCamera()
	local playerCharacter = player.Character
	local playerCameraSubject = playerCharacter.Humanoid
	if playerCharacter then
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
		local cameraTween = TweenService:Create(camPart.CFrame, tweenInfo, {["CFrame"] = playerCameraSubject})
		cameraTween:Play()
		cam.CameraType = Enum.CameraType.Custom
	end
end

camPart is still defined, correct? Double check if it’s still a variable.

1 Like

camPart is still defined
image

Also, I now only get this error: 14:49:57.441 Unable to cast value to Object - Client - CameraMenu:33

Ah, then the problem is that you forgot to add “.CFrame” at the end of playerCameraSubject. (should’ve probably clarified mb i’m like super sleep deprived rn)

1 Like

no problem, it s also my fault for being so dumb.

now that i added .CFrame after playerCameraSubject i get the following error:

14:57:25.141 CFrame is not a valid member of Humanoid “Workspace.playername.Humanoid” - Client - CameraMenu:33

local function transitionToPlayerCamera()
	local playerCharacter = player.Character
	local playerCameraSubject = playerCharacter.Humanoid
	if playerCharacter then
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
		local cameraTween = TweenService:Create(camPart.CFrame, tweenInfo, {["CFrame"] = playerCameraSubject.CFrame})
		cameraTween:Play()
		cam.CameraType = Enum.CameraType.Custom
	end
end

Also forgot to realize that it’s playerCameraSubject.CFrame and not originalCameraCFrame.CFrame, should change that back.

1 Like

like this?

local function transitionToPlayerCamera()
	local playerCameraSubject = player.Character:FindFirstChild("Humanoid")
	local playerCharacter = player.Character
	if playerCharacter then
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
		local cameraTween = TweenService:Create(camPart.CFrame, tweenInfo, {["CFrame"] = originalCameraCFrame})
		cameraTween:Play()
		cam.CameraType = Enum.CameraType.Custom
	end
end

Should work, accidently said originalCameraCFrame.CFrame and not just originalCameraCFrame

15:14:19.357 Unable to cast value to Object - Client - CameraMenu:33

Sadly, it doesn’t

If you would like to give up I would totally understand that.

Maybe I could make a animation instead with a plugin

Realized I made another mistake, thought camPart was workspace.CurrentCamera for some reason.

local cameraTween = TweenService:Create(cam, tweenInfo, {["CFrame"] = originalCameraCFrame})
1 Like

Sorry for the late response, it works now but the tween doesn t start from where the main menu camera was and from the players camera.

I could leave it like this i guess but it s not that great

If you would like to still help, i would be glad. I put your first answer as solution.

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