Why is this error occuring?

I have a script for my main menu and it includes a while true loop that cycles between camera tweens randomly to make cool camera movement. However it sometimes gives out an error and I have no idea what it means. I’m guessing it has to do something with tweening the camera? I don’t know.
This is what the error states:

Players.1z25_3.PlayerScripts.PlayerModule.CameraModule.BaseCamera:799: invalid argument #3 to ‘clamp’ (max must be greater than or equal to min)

Here’s the video showing the problem, notice how the error is not guaranteed: (Please ignore the black screen at the start and skip to the minute mark or so)

And here are parts of my script that control the camera:

local function cycleCams()
	playerCam.CameraType = Enum.CameraType.Scriptable
	while true do
		local startCams = cams.StartTween:GetChildren()
		local startCam = startCams[math.random(1, #startCams)]
		local endCam = cams.EndTween:FindFirstChild(startCam.Name)

		playerCam.CFrame = startCam.CFrame
		tween = tweenService:Create(playerCam, TweenInfo.new(5, Enum.EasingStyle.Linear), {CFrame = endCam.CFrame})
		tween:Play()
		task.wait(5)
	end
end

local function openMenu()
	menu.Enabled = true
	
	module.playerMovement(player, "Halt")
	thread = task.spawn(cycleCams)
	
	local gameGui = player.PlayerGui:FindFirstChild("GameGui")
	if gameGui then
		gameGui.Enabled = false
	end
	game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	
	menuTween()
end

local function closeMenu()
	local blackout = player.PlayerGui:FindFirstChild("Blackout").Frame	
	for x = 1, 20, 1 do
		blackout.Transparency -= 0.05
		task.wait(0.05)
	end
	
	menu.Enabled = false

	if replicatedStorage:FindFirstChild("SessionStats"):GetAttribute("Gamemode") ~= "None" then module.playerMovement(player) end

	task.cancel(thread)
	tween:Cancel()
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	game.Workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
	
	local gameGui = player.PlayerGui:FindFirstChild("GameGui")
	if not gameGui then
		gameGui = replicatedStorage:WaitForChild("Gui").GameGui:Clone()
		gameGui.Parent = player.PlayerGui
	else
		gameGui.Enabled = true
	end
	game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
	
	for x = 1, 20, 1 do
		blackout.Transparency += 0.05
		task.wait(0.05)
	end
end

If you need more details to help, let me know

4 Likes

can you show me the snippet of the section of the code that cause error (line number)

1 Like
function BaseCamera:CalculateNewLookCFrameFromArg(suppliedLookVector: Vector3?, rotateInput: Vector2): CFrame -- line 799
	local currLookVector: Vector3 = suppliedLookVector or self:GetCameraLookVector()
	local currPitchAngle = math.asin(currLookVector.Y)
	local yTheta = math.clamp(rotateInput.Y, -MAX_Y + currPitchAngle, -MIN_Y + currPitchAngle)
	local constrainedRotateInput = Vector2.new(rotateInput.X, yTheta)
	local startCFrame = CFrame.new(ZERO_VECTOR3, currLookVector)
	local newLookCFrame = CFrame.Angles(0, -constrainedRotateInput.X, 0) * startCFrame * CFrame.Angles(-constrainedRotateInput.Y,0,0)
	return newLookCFrame
end

function BaseCamera:CalculateNewLookVectorFromArg(suppliedLookVector: Vector3?, rotateInput: Vector2): Vector3
	local newLookCFrame = self:CalculateNewLookCFrameFromArg(suppliedLookVector, rotateInput) -- line 807
	return newLookCFrame.LookVector
end
2 Likes

Are you sure MIN_Y is smaller than MAX_Y? I see you inversed the number but this might be the case, can you add more debugging by printing out those two values.

2 Likes

I never changed anything with these scripts, they came default within Roblox I believe. Where exactly do I print you the values you want? (where in the code)

1 Like

local yTheta = math.clamp(rotateInput.Y, -MAX_Y + currPitchAngle, -MIN_Y + currPitchAngle) Right above this line, print MAX_Y and MIN_Y

1 Like

I wrote “print(MAX_Y, MIN_Y)” right above and it doesn’t seem to be printing anything? Im afraid im doing it wrong.

1 Like

Could you please click on the error on the output. This will take you to the line it was executed at, after that could you give me that line of script?

1 Like

Print in luau only takes one value at a time and silently fails otherwise because roblox likes to not use global debugging standards. Try print(string.format("MIN_X: %f ,MIN_Y: %f" , MIN_X, MIN_Y))

1 Like

I am afraid that might not be true.

1 Like

I read this wrong. No, you can print multiple statements at once.

1 Like

Yes, it’s line 799 in the reply I showed earlier. There are other scripts, here is the full “stack”.

1 Like

Hmm could you please inverse -MAX_Y AND -MIN_Y turning them into MAX_Y and MIN_Y then try again?

I don’t know if I can do that to fix the problem! The camera module is part of a player module which only appears once I spawn in, meaning I only know to modify it in-game. Which also could be the reason why the prints weren’t working. It’s not part of startercharacter, either.

Out if curiosity, where is this camera module you talk about coming from? In the filter bar of your Explorer, type “Script”, then search through your scripts for any mentions of Clone() you don’t know about. The Toolbox does not only contain Roblox-created content, so you might be uaing a camera module someone else created.

(If it’s a model you inserted from Toolbox, your camera module will very likely be within Workspace)

Could you provide me with a screenshot of everything inside this cams folder / model from this line of your script:

local startCams = cams.StartTween:GetChildren()
local startCam = startCams[math.random(1, #startCams)]
local endCam = cams.EndTween:FindFirstChild(startCam.Name)

Also have you made any changes to your clone of ROBLOX’s camera module?

It’s in StarterPlayerScripts, PlayerModule, the default module Roblox uses (or atleast I assume so because it just pops out of nowhere without any help of mine or toolbox). I do not use any toolbox camera modules.

I have not made any changes to it and I didn’t clone it, I was not aware of this module’s existence before I encountered this error. Here’s the folder, it’s in ReplicatedStorage:
image
It’s just bricks that I placed around the map so that I can use their positions to tween the camera.

Not a virus I have either! This “PlayerModule” also appears when I load into a completely new place.

Unfortunately I was not able to replicate your issue. I tested your script and a similar setup, it worked perfectly fine for me. Do you have any other script that controls the camera?