The script is supposed to tween the players to a camera part in front of the npc, and is supposed to tween back to the player when ran again, but I am getting an error on line 26, how do I fix this and if there's a better way to do this, how?

local tweenService = game:GetService("TweenService")
local currentCamera = workspace.CurrentCamera
local isViewing = false
local originCameraCFrame = nil
local camPart = game.Workspace.CameraPart
local playerCam = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Chraracter = Player.Character or Player.CharacterAdded:Wait()
local npc = game.Workspace.MOREHOURSOFFUN.ClickDetector
local closeGui = game.StarterGui.shopGui.closeGui

function onClick()
	if not isViewing then
		isViewing = true
		currentCamera.CameraType = Enum.CameraType.Scriptable
		originCameraCFrame = currentCamera.CFrame
		local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0)
		local tweenGoal = {CFrame = camPart.CFrame}
		local tweenAnim = tweenService:Create(currentCamera, tweenInfo, tweenGoal)
		tweenAnim:Play()
	elseif isViewing then
		isViewing = false
		currentCamera.CameraType = Enum.CameraType.Scriptable
		local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.In)
		local tweenGoal = {playerCam}
		local tweenBackAnim = tweenService:Create(currentCamera, tweenInfo, tweenGoal)
		tweenBackAnim:Play()
		tweenBackAnim.Completed:Connect(function(playbackState)
			currentCamera.CameraType = Enum.CameraType.Custom
		end)
	end
end

npc.MouseClick:Connect(onClick)

2 comments

1

try doing local tweenGoal = {CFrame = playerCam.CFrame} on line 25

0

It worked, thanks