Workspace:GetDescendants() is only returning a camera instance and I cannot figure out why.
Here is my script (on the client), I cannot seem to figure out why this script is not working. It’s located in StarterGui so it would be running under the player’s PlayerGui as a local script.
local UserInputService = game:GetService("UserInputService")
local PlayerService = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
---
local Player : Player = PlayerService.LocalPlayer
local Camera : Camera = workspace.CurrentCamera
local Info_Folder : Folder = Player:WaitForChild("Info")
local Character : Model = Player.Character or Player.CharacterAdded:Wait()
local Humanoid : Humanoid = Character:WaitForChild("Humanoid")
---
--
local Parts = {}
RunService . RenderStepped : Connect (function(dT)
if not Info_Folder:GetAttribute("AutoAim") then return end
for i, V_1 in pairs(workspace:GetDescendants()) do
print(V_1)
--- Irrelevant functions past this point
if not V_1:IsA("Model") then return end print("model")
if not V_1:FindFirstChildOfClass("Humanoid") then return end print("humanoid")
print("hi")
local Position = Camera:WorldToViewportPoint(V_1.PrimaryPart.Position)
local Center = Camera.ViewportSize / 2
table.insert(Parts, {
Block = V_1;
Distance = (Center - Vector2.new(Position.x, Position.y)).Magnitude
})
end
table.sort(Parts, function(a, b)
return a.Distance < b.Distance
end)
end)
Here’s what is supposed to show up in the workspace. I want the script to print the closest character to the model, however I believe that is not relevant and my scripting is correct- it is just the :GetDescendants() that does not seem to function properly but I have attached it incase it might have function.