Hey! I am currently making a project and i want to know how do i load a random friend character in R6?
I would appreciate any kind of support.
Hey! I am currently making a project and i want to know how do i load a random friend character in R6?
I would appreciate any kind of support.
local description = game.Players:GetHumanoidDescriptionFromUserId(1387374449)
game.Players:CreateHumanoidModelFromDescription(description,Enum.HumanoidRigType.R6,"Default")
Expanding off of the API for obtaining friends from a UserID, explained well by this post: Getting a players friends - #4 by ForeverHD
And expanding off of Auburn’s post.
local fID = 0 --UserID to search for friends from
local FriendTable = {}
local Success,FriendPage = pcall(function() --Protected call to prevent errors. Better safe than sorry.
return game.Players:GetFriendsAsync(fID) --Obtain all friends from the previously stated fID variable.
end)
if Success then
repeat
local PageInfo = FriendPage:GetCurrentPage() --Gets the current page of friends.
for Index,FriendInfo in pairs(PageInfo) do --Iterates through the page and adds the info from each friend to "FriendTable".
table.insert(FriendTable,FriendInfo) --Insert to "FriendTable".
end
if not FriendPage.IsFinished then --If there are still pages left, continue iterating
FriendPage:AdvanceToNextPageAsync() --Advance to next page
end
until FriendPage.IsFinished --Once finished, halt the repeat
end
local FriendInfo = FriendTable[math.random(1,#FriendTable)] --Obtain FriendInfo from the "FriendTable" using our current Index. math.random to pick a random friend. (# operator obtains the length of tables without keys)
local FriendDescription = game.Players:GetHumanoidDescriptionFromUserId(FriendInfo["Id"]) --Basing off of the previous post! Obtain the HumanoidDescription from the UserID of the randomly picked friend.
local FriendCharacter = game.Players:CreateHumanoidModelFromDescription(FriendDescription,Enum.HumanoidRigType.R6,"Default") --Applies the previously obtained HumanoidDescription to a PlayerModel which is generated from game.Players. (Set to spawn as R6)
--Do whatever with FriendCharacter
This code is untested for errors because my Intellisense is currently broken, so please troubleshoot this before using it!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.