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
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
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.
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.
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
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.