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)
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
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})
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
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)
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
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