Hey guys! I was using this code to change the player’s camera and to also animate it, based on the sent targetPart.
-- Listen for the server event
Events.CameraEvent.OnClientEvent:Connect(function(targetPart, tweeningNeeded)
print(targetPart, tweeningNeeded)
if targetPart then
if not targetPart:IsA("BasePart") then return end
-- Switch to Scriptable camera and store the target
Camera.CameraType = Enum.CameraType.Scriptable
if tweeningNeeded then -- if tweening needed tween camera
if Camera.CFrame == targetPart.CFrame then return end -- if same cframe return
local toTween = TweenService:Create(
Camera, TweenInfo.new(1), {CFrame = targetPart.CFrame}
)
toTween:Play()
else -- if not just set to position
Camera.CFrame = targetPart.CFrame
end
else
local Character = Player.Character
if not Character or not Character.Parent then return end
local Humanoid = Character:FindFirstChild("Humanoid")
local HRP = Character:FindFirstChild("HumanoidRootPart")
if not Humanoid or not HRP then return end
-- Reset camera to follow the player
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Humanoid
end
end)
Well this script went wild a couple of times, when it keeps repeating this:
Players.Player3.PlayerScripts.PlayerModule.CameraModule.BaseCamera:732: invalid argument #3 to ‘clamp’ (max must be greater than or equal to min)
RunService:fireRenderStepEarlyFunctions unexpected error while invoking callback: Players.Player3.PlayerScripts.PlayerModule.CameraModule.BaseCamera:732: invalid argument #3 to ‘clamp’ (max must be greater than or equal to min)
This is printed every single frame. Can happen for any player.
Later I updated the code to this:
-- Listen for the server event
Events.CameraEvent.OnClientEvent:Connect(function(targetPart, tweeningNeeded)
print(targetPart, tweeningNeeded)
if targetPart then
if not targetPart:IsA("BasePart") then return end
-- Switch to Scriptable camera and store the target
Camera.CameraType = Enum.CameraType.Scriptable
if tweeningNeeded then -- if tweening needed tween camera
if Camera.CFrame == targetPart.CFrame then return end -- if same cframe return
local toTween = TweenService:Create(
Camera, TweenInfo.new(1), {CFrame = targetPart.CFrame}
)
toTween:Play()
else -- if not just set to position
Camera.CFrame = targetPart.CFrame
end
else
local Character = Player.Character
if not Character or not Character.Parent then return end
local Humanoid = Character:FindFirstChild("Humanoid")
local HRP = Character:FindFirstChild("HumanoidRootPart")
if not Humanoid or not HRP then return end
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = HRP.CFrame
task.wait() -- short delay
-- Reset camera to follow the player
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Humanoid
end
end)
It works fine mostly now, sometimes it does the same thing when the player’s camera is updated while the player is dead. (Health <= 0)
Does anyone have an idea why does this happen? I’ve read about this here but haven’t really found anything useful. Have you had experience with this before?
Just to note, the event is not spammed, it is only called once (not like 10 times in half a second) - so I ruled out this part as being the problem.