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
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
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.
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)
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?
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))
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:
It’s just bricks that I placed around the map so that I can use their positions to tween the camera.
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?