Attempt to compare userdata and number?

Can’t find the error within this code, I printed typeof(size) and (position) and always returned Vector3, so for some reason is not working right

local function GetCameraInChunk()
		
			  if HRP and Character.Humanoid.Health > 0 then
				local Size,Position = workspace.Model:GetExtentsSize(),workspace.Model:GetBoundingBox().Position
			
			--[[ERROR HERE]]	if Player:DistanceFromCharacter(Position) >= Size*2 then
					UnloadChunk(workspace.Model)
					LastChunk = workspace.Model
					print('Is far')
					elseif Player:DistanceFromCharacter(Position) <= Size*2 then
						if StoredChunks[workspace.Model] == true then
							LastChunk = workspace.Model
							LoadChunk(workspace.Model)
							print('Is close')
						end
				end
			end
			return nil
		
	end
	

Player:DistanceFromCharacter(Position) returns a float, not a Vector3 value. Thus, it fails to compare a number with a vector!

I’m not quite sure what you are trying to check there, but 2·Size.Magnitude (instead of 2·Size) might be what you need in both cases (Magnitude is a distance).

What do you mean? if when I printed typeof it was printing Vector3 :thinking:
How can I fix it, using root part - position.Magnitude, I’m trying to check if the HumanoidRootPart is a little bit far away of the Model position

Check the whole statement, since you are not comparing Size with Position but with the distance (a number) from the player to a point in 3D world. Try this instead:

typeof(Player:DistanceFromCharacter(Position)) --> number

You could do:

if Player:DistanceFromCharacter(Position) >= 2*Size.Magnitude then

This will return true if the player is closer to the center of the model than the double of the distance between the two farthest points of the model bounding box. The bigger the model, the longer the distance the player should be in.

local Size,Position = workspace.Model:GetExtentsSize(),workspace.Model:GetBoundingBox().Position
if Player:DistanceFromCharacter(Position) >= Size*2 then

You’re trying to compare a Vector3 (Size*2) with a float value. You cannot do this. Size needs to be a float value as well instead of a Vector3.

It’s still erroring the same
attempt to compare number and userdata

14:27:36.053 - Stack Begin

How can I make that? isn’t Model:GetExtentsSize() a Vector3?

Yes, it is. That’s your issue. Player:DistanceFromCharacter() is not.

Edit: just as another tip, I wouldn’t use Player:DistanceFromCharacter() because it has weird behavior and can potentially mess up your systems if the character is dead/head is missing. I’d just use a .magnitude call instead.

Did you replace both statements? You are doing the same a few lines underneath.

It’s causing the error again

if (HRP.Position - Position) >= 2*Size.Magnitude then

Add .magnitude after the closing bracket

Still causing same error

if (HRP.Position - Position).Magnitude >= Size.Magnitude*2 then

It’s weird

Did you fix both of the lines?

What do you mean?
This is my current code

local function GetCameraInChunk()
		
			  if HRP and Character.Humanoid.Health > 0 then
				local Size,Position = workspace.Model:GetExtentsSize(),workspace.Model:GetBoundingBox().Position
			
				if (HRP.Position - Position).Magnitude >= Size.Magnitude/2 then
					UnloadChunk(workspace.Model)
					LastChunk = workspace.Model
					print('Is far')
					elseif Player:DistanceFromCharacter(Position) <= Size*2 then
						if StoredChunks[workspace.Model] == true then
							LastChunk = workspace.Model
							LoadChunk(workspace.Model)
							print('Is close')
						end
				end
			end
			return nil
		
	end

elseif Player:DistanceFromCharacter(Position) <= Size*2 then

You didn’t change this line.

OH!!! That’s wy it’s causing error lol…

Output is your best friend. Always keep an eye out for the line of code it throws an error on.

Also, quick question, if I have like 6 Chunks, and the models are kinda big, would it lag? Also, if I group model inside the model it will still work?

Will it lag? it’s a while true do loop.

If I understand what you’re asking for, that depends on the device. If it’s a ton of parts, it might lag for a low-end device. While loops can cause lag in the task scheduler

So, how games as jailbreak, and Apocalypse rising do this? like chunk loading, because they have a lot of parts, and many people plays it, and I think they have the system.