for _, v in pairs(workspace:GetChildren()) do
if v:IsA('Model') and v:FindFirstChild('HumanoidRootPart') and player.Character ~= v then
print(v, v.Name)
print(game.Players:GetPlayerFromCharacter(v))
local gui = creatBlip(v.Name)
table.insert(parts, {v.HumanoidRootPart, gui})
end
end
Line 3 prints Player2 Player2 (one being the character, other being their name, duh)
Line 4 however prints nil… And I am completely stumped as to why? If it’s printing v as Player2, then it should be able to get the character from Players. This is in a LocalScript btw.
Why not just iterate through the children of Players rather than the whole of workspace?
for _, v in pairs(game.Players:GetPlayers()) do
if player ~= v then
local char = v.Character
local gui = creatBlip(char.Name)
table.insert(parts, {char.HumanoidRootPart, gui})
end
end
I agree with @CodeSleepRepeat; you should iterate through the Players themselves instead.
As to your question: It looks like your code is working as expected. It’s printing the character model name twice on one line, and then printing the player’s name on the next line. The first nil is probably coming from some other script (unless there’s more to this script not shown).