The parts probably did not load in yet so you could add some code to wait until they load in before using :GetChildren() and also you do not need the brackets ({}) when using GetChildren() like that.
i added a wait(2) but now i have a new error! sorry for wasting your time btw
ERROR:
line of code error is located:
Can you remove the brackets here? It should be local Parts = game.Workspace.A:GetChildren()
it works! but it only loads one
This spawns a friend’s character every 5 seconds or so but you should go ahead and change its behavior for what you want
task.wait()
function SpawnFriend()
local PlayersService = game:GetService("Players")
local LocalPlayer = PlayersService.LocalPlayer
local FriendIDs = {}
local success, fail pcall(function()
local friendsList = PlayersService:GetFriendsAsync(LocalPlayer.UserId)
for page=1,4 do
for _,friend in pairs(friendsList:GetCurrentPage()) do
table.insert(FriendIDs, friend.Id)
end
if page ~= 4 then
local pass,err = pcall(function()
friendsList:AdvanceToNextPageAsync()
end)
if not pass then
break
end
end
end
end)
task.wait(2)
local Parts = workspace:WaitForChild("A"):GetChildren()
local function GetRandomFriend()
return FriendIDs[math.random(1, #FriendIDs)]
end
local SelectedFriend = GetRandomFriend()
local FriendCharacter = PlayersService:CreateHumanoidModelFromUserId(SelectedFriend)
for i,v in pairs(Parts) do
v.CanCollide = false
end
FriendCharacter:PivotTo(Parts[math.random(1, #Parts)].CFrame)
FriendCharacter.Parent = workspace
end
while true do
local success, err = pcall(SpawnFriend)
task.wait(3)
end
This will help tons! but is there a way to load them in all at once?
task.wait()
function SpawnAllFriends()
local PlayersService = game:GetService("Players")
local LocalPlayer = PlayersService.LocalPlayer
local FriendIDs = {}
local success, fail pcall(function()
local friendsList = PlayersService:GetFriendsAsync(LocalPlayer.UserId)
for page=1,4 do
for _,friend in pairs(friendsList:GetCurrentPage()) do
table.insert(FriendIDs, friend.Id)
end
if page ~= 4 then
local pass,err = pcall(function()
friendsList:AdvanceToNextPageAsync()
end)
if not pass then
break
end
end
end
end)
task.wait(2)
local Parts = workspace:WaitForChild("A"):GetChildren()
for i,v in pairs(Parts) do
v.CanCollide = false
end
for _,ID in pairs(FriendIDs) do
local success, err = pcall(function()
local FriendCharacter = PlayersService:CreateHumanoidModelFromUserId(ID)
FriendCharacter:PivotTo(Parts[math.random(1, #Parts)].CFrame)
FriendCharacter.Parent = workspace
end)
if not success then
warn("Could not spawn "..ID.."'s character becasue: "..err)
end
end
end
SpawnAllFriends()
It doesn’t stop loading them because it’s in a while loop (meaning it will run forever) which is why you should tinker with the code to get it to do what you want it to do.
Sorry! my small brain is not big enough to comprehend with :GetFriendsAsync() lol, sorry to bother you but im still confused on how to make it so 1 spawns on each part and stops spawning when all the parts have a character pivoted to them
Hey! if u need help knowing what i mean, look at this game:
You would probably need 200 parts to do that since you can have a max of 200 friends which is not really optimal. So I would create a part and spawn a friend’s character to it then for each friend I slightly move the next part’s position
task.wait()
function SpawnAllFriends()
local PlayersService = game:GetService("Players")
local LocalPlayer = PlayersService.LocalPlayer
local FriendIDs = {}
local success, fail pcall(function()
local friendsList = PlayersService:GetFriendsAsync(LocalPlayer.UserId)
for page=1,4 do
for _,friend in pairs(friendsList:GetCurrentPage()) do
table.insert(FriendIDs, friend.Id)
end
if page ~= 4 then
local pass,err = pcall(function()
friendsList:AdvanceToNextPageAsync()
end)
if not pass then
break
end
end
end
end)
task.wait(2)
local Parts = workspace:WaitForChild("A"):GetChildren()
local PreviousPart
for i,v in pairs(Parts) do
v.CanCollide = false
end
for _,ID in pairs(FriendIDs) do
local success, err = pcall(function()
local FriendCharacter = PlayersService:CreateHumanoidModelFromUserId(ID)
if not PreviousPart then
PreviousPart = Parts[math.random(1, #Parts)]
else
local PreviousPosition = PreviousPart.Position
PreviousPart = Instance.new("Part")
PreviousPart.CanCollide = false
PreviousPart.Anchored = true
PreviousPart.Position = Vector3.new(PreviousPosition.X + 6, PreviousPosition.Y, PreviousPosition.Z)
PreviousPart.Parent = workspace
end
FriendCharacter:PivotTo(PreviousPart.CFrame)
FriendCharacter.Parent = workspace
end)
if not success then
warn("Could not spawn "..ID.."'s character because: "..err)
end
end
end
SpawnAllFriends()
oh, that really isnt optional. Can you modify the script a bit to make it so it applies a character description to every rig in a folder?
You probably need to put this in a server script because I think ApplyDescriptionReset() can only be used on the server if used on non local rigs.
task.wait()
function SpawnAllFriends(UserId)
local PlayersService = game:GetService("Players")
local FriendIDs = {}
local success, fail pcall(function()
local friendsList = PlayersService:GetFriendsAsync(UserId)
for page=1,4 do
for _,friend in pairs(friendsList:GetCurrentPage()) do
table.insert(FriendIDs, friend.Id)
end
if page ~= 4 then
local pass,err = pcall(function()
friendsList:AdvanceToNextPageAsync()
end)
if not pass then
break
end
end
end
end)
local Rigs = workspace.Rigs
for i, Rig in pairs(Rigs:GetChildren()) do
local success, err = pcall(function()
local TargetHumanoid = Rig:FindFirstChildWhichIsA("Humanoid")
if TargetHumanoid then
TargetHumanoid:ApplyDescriptionReset(PlayersService:GetHumanoidDescriptionFromUserId(FriendIDs[i]))
end
end)
if not success then
warn("Could not spawn "..FriendIDs[i].."'s character because: "..err)
end
end
end
SpawnAllFriends(USERID) -- Your userId here
Oof, i need this to be local? would it be easier if i sent you a game i found which is exactly what im trying to replicate?
This is correct but once again. i need this to be the player id. not a specific user’s
This is the most I can do for you but if you wanna learn to program your own custom behavior I really do recommend getting familiar with Roblox Lua found here
task.wait()
local PlayersService = game:GetService("Players")
function SpawnAllFriends(UserId)
local FriendIDs = {}
local success, fail pcall(function()
local friendsList = PlayersService:GetFriendsAsync(UserId)
for page=1,4 do
for _,friend in pairs(friendsList:GetCurrentPage()) do
table.insert(FriendIDs, friend.Id)
end
if page ~= 4 then
local pass,err = pcall(function()
friendsList:AdvanceToNextPageAsync()
end)
if not pass then
break
end
end
end
end)
task.wait(2)
local Rigs = workspace.Rigs
for i, Rig in pairs(Rigs:GetChildren()) do
local success, err = pcall(function()
local TargetHumanoid = Rig:FindFirstChildWhichIsA("Humanoid")
if TargetHumanoid then
TargetHumanoid:ApplyDescriptionReset(PlayersService:GetHumanoidDescriptionFromUserId(FriendIDs[i]))
end
end)
if not success then
warn("Could not spawn "..FriendIDs[i].."'s character because: "..err)
end
end
end
for i,v in pairs(PlayersService:GetPlayers()) do
SpawnAllFriends(v.UserId)
end
PlayersService.PlayerAdded:Connect(function(player)
SpawnAllFriends(player.UserId)
end)
Oh, alright. i might just leave the game in the back of my mind for now till i can figure out how to do this.
Just in case it helps you to figure out what i mean (or if u cant and just want to give up that doesn’t matter) here is the game link that i mean when load the players friends avatar onto a rig:
task.wait()
function SpawnAllFriends()
local PlayersService = game:GetService(“Players”)
local LocalPlayer = PlayersService.LocalPlayer
local FriendIDs = {}
local success, fail pcall(function()
local friendsList = PlayersService:GetFriendsAsync(LocalPlayer.UserId)
for page=1,4 do
for _,friend in pairs(friendsList:GetCurrentPage()) do
table.insert(FriendIDs, friend.Id)
end
if page ~= 4 then
local pass,err = pcall(function()
friendsList:AdvanceToNextPageAsync()
end)
if not pass then
break
end
end
end
end)
task.wait(2)
local Parts = workspace:WaitForChild("A"):GetChildren()
for i,v in pairs(Parts) do
v.CanCollide = false
end
for _,ID in pairs(FriendIDs) do
local success, err = pcall(function()
local FriendCharacter = PlayersService:CreateHumanoidModelFromUserId(ID)
FriendCharacter:PivotTo(Parts[math.random(1, #Parts)].CFrame)
FriendCharacter.Parent = workspace
end)
if not success then
warn("Could not spawn "..ID.."'s character becasue: "..err)
end
end
end
SpawnAllFriends()
Hey! this script would work. but how could i make it so it would only spawn 1 friend at each part then stop?