Error Within a Script

It might be the Pivot, print pivot
print(Pivot)
And remove the previous print statement

Yep, it is returning as nil.
image
Imma be honest I have no clue how to fix it lol.

Post your current code, you must’ve changed something with how you’re calling the functions.

Yep it was your pivot, okay so basically right here this line:

followMouse( CFrame.new() ) -- Pass a CFrame where the camera is locked

Your CFrame is nil, you have no value, since I’m assuming your trying to get the pivot of the mouse then instead of this you’d do

followMouse(plr:GetMouse())
local tween = game:GetService'TweenService'
local uis = game:GetService'UserInputService'
local run = game:GetService('RunService')

local cam = workspace.Camera
local plr = game.Players.LocalPlayer

local screenX = cam.ViewportSize.X
local screenY = cam.ViewportSize.Y

local MOVE_SPEED = 4
local MAX_ANGLE_X = math.rad(45)
local MAX_ANGLE_Y = math.rad(20)

local followConnect:RBXScriptConnection
local function followMouse(Pivot: CFrame)
	print(Pivot)
	local t = tween:Create(cam,TweenInfo.new((cam.CFrame.Position-Pivot.Position).Magnitude/10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = CFrame.new(1,1,1)})
	t:Play()
	t.Completed:Wait()
	task.wait(1)

	local pos = uis:GetMouseLocation()
	followConnect = run.RenderStepped:Connect(function(dt)
		pos = pos:Lerp(uis:GetMouseLocation(),dt*MOVE_SPEED)
		local x = pos.X/screenX*2-1
		local y = pos.Y/screenX*2-1
		cam.CFrame = Pivot*CFrame.Angles(0,x*MAX_ANGLE_X,0)*CFrame.Angles(y*MAX_ANGLE_Y,0,0)
	end)
end

followMouse( ) -- Pass a CFrame where the camera is locked
followConnect:Disconnect() -- Stop mouse follow```

Alright, I’ll try that. charssss

Half of it works, the only thing is now is that the camera goes in the opposite direction of the mouse and that there is a piece of time that the camera randomly resets rather than smoothly tweening into the part.

External Media

To fix it from going to the opposite position, instead of subtracting in your tween. Try adding:

local t = tween:Create(cam,TweenInfo.new((cam.CFrame.Position+Pivot.Position).Magnitude/10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = CFrame.new(1,1,1)})
1 Like

Same thing, I have to go I’ll message you if thats okay later about this.

Thanks so much for your help and patience.

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