Error Within a Script

Hello, I am currently in the process of making a game and in order to achieve a system I’m using a script made on here from a year ago. Back then I was a better scripter and was able to diagnose the problem, now I am unable to.

SCRIPT:

local tween = game:GetService'TweenService'
local uis = game:GetService'UserInputService'

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)
	local t = tween:Create(cam,TweenInfo.new((cam.CFrame.p-Pivot.Position).Magnitude/10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut))
	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( CFrame.new() ) -- Pass a CFrame where the camera is locked
followConnect:Disconnect() -- Stop mouse follow```

Error message is within the embedded part of the script, here it is out of it.

Error Message: Argument 3 missing or nil - Client - LocalScript:17

The reason you’re getting this error is because you’re not setting what properties you want to be tweened. Tween:Create() requires the instance, TweenInfo, and the properties to tween. To fix this, take this line

local t = tween:Create(cam,TweenInfo.new((cam.CFrame.p-Pivot.Position).Magnitude/10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{PropertyName = Value})

and change PropertyName to whatever property and Value to whatever you want the end value to be. :slight_smile:

Thank you, I’ll get back to see if it works.

No worries :slight_smile: Glad to be able to help!

It’s saying that “run” after followConnect is nil.

Oh, that’s because you’re not declaring what the variable “run” is – put this at the top of the script:

local run = game:GetService('RunService')

That’ll fix that issue. :slight_smile:

Sorry for all the questions still, I’ve just gone WAY out of scripting for the past year.

I’m trying to make a system similar to this, Gyazo, where it is a camera and I have no idea what to address the variables as, being that it should rotate around a part.

Thanks, and again sorry for my lack of knowledge lol.

No worries! :slight_smile:

Well, typically for naming variables, you should go with names that are easy to look back and at the code and know exactly what each variable relates to – for instance, with RunService, I would suggest naming that variable “RunService”. :slight_smile:

Thanks for the help!

I’m also curious as to what I would name for the blank value you suggested in the tween itself, also as to what the object would be.

Oh… Well, since you’re wanting to tween the Camera, it has to be a property of the camera itself. So for what you’re wanting to do, it would be CFrame = CFrame.new(X,Y,Z) where X,Y,Z are the coordinates of each axis.

Here we go with more errors lol.


I’m sorry I’m putting you through all this.

Did you put your variables inside it? I’m not sure if that’s what WrollingYou was suggesting you do, but he did say that X,Y,Z are the coordinates of each axis, which to me implies that you need to put your variables inside it. I could be wrong though.

1 Like

In my example, X,Y,Z were just placeholders – not actual values. You’d have to figure the coordinates you want. You’d also want to use CFrame.Angles() in combination with CFrame.new() to get it to turn left / right / up / down.

I did put values in the XYZ, I did 1,1,1 just for the sake of time.
image

I think it might be related to this.
image

P is deprecated. Try changing p to Position.

Same thing, here is the whole line and error msg.

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

Whenever you get an attempt to index nil error, it’s always good to make sure your variables aren’t nil, so one way that would help you debug and figure this out is by printing all the variables you’re using on that line. Try printing
print(cam, cam.CFrame, Pivot}
Print that before line 17, and show me the output.

Could you post your current code? I’m guessing Pivot is no longer defined.