i have 2 characters in a van that i want to apply a friends character to, at random for both but im getting an error. im not very experienced at humanoiddescription so. ty!
script:
--get friends:
local PageInstance = game.Players:GetFriendsAsync(plr.UserId):GetCurrentPage()
local vanCharacters = {vanClone.chainsawMan, vanClone.Rig}
for i, friendsChar in pairs(PageInstance) do
local CharFriendsDesc = friendsChar:GetHumanoidDescriptionFromUserId(friendsChar.UserId)
for i, vanChar in pairs(vanCharacters) do
vanChar.Humanoid:ApplyDescription(CharFriendsDesc)
end
end
Each value in the returned table from :GetCurrentPage() is info of each friend
first replace friendsInfo.UserId with Id. There is also no method called “GetHumanoidDescriptionFromUserId” in these tables, but there is in Players service.
Here’s the corrected code which should work.
local PageInstance = game.Players:GetFriendsAsync(plr.UserId):GetCurrentPage()
local vanCharacters = {vanClone.chainsawMan, vanClone.Rig}
for i, friendsChar in PageInstance do
local CharFriendsDesc = game.Players:GetHumanoidDescriptionFromUserId(friendsInfo.Id)
for i, vanChar in pairs(vanCharacters) do
vanChar.Humanoid:ApplyDescription(CharFriendsDesc)
end
end
but this doesnt seem to get a random friend’s character so here i wrote some code for you
local UserId = 1057895133
local Friends
local Friend1, Friend2
local Friend1HumanoidDescription, Friend2HumanoidDescription
local success, err = pcall(function()
Friends = game.Players:GetFriendsAsync(UserId):GetCurrentPage()
warn(Friends)
assert(#Friends ~= 0, `{UserId} has no friends`)
Friend1 = Friends[math.random(#Friends)].Id
Friend2 = Friends[math.random(#Friends)].Id
Friend1HumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(Friend1)
Friend2HumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(Friend2)
end)
if not success then warn(err) end
local Humanoid1: Humanoid = nil -- location of the first humanoid in the van
local Humanoid2: Humanoid = nil -- location of the second humanoid in the van
Humanoid1:ApplyDescription(Friend1HumanoidDescription)
Humanoid2:ApplyDescription(Friend2HumanoidDescription)
hello! tysm 4 helping me! the first script works amazing however the second script doesnt unfortunately.
the first one loops thru all the characters then chooses the same one. i did some tinkering but it pretty much does the same thing. i want it to choose a random character for each one do u know how u would do that?
hey so the problem with your first script is that it iterates through each friend in the and sequentially sets the HumanoidDescription of the characters in the van to the current iterated friend, eventually the last friend would be the one you see selected (until u run function again). You said you wanted the HumanoidDescriptions to be of a random friend in the list so here’s some edited code let me know if it works!
--get friends:
local PageInstance = game.Players:GetFriendsAsync(plr.UserId):GetCurrentPage()
local vanCharacters = {vanClone.chainsawMan, vanClone.Rig}
for i, vanChar in pairs(vanCharacters) do
local randomHumanoidDescription
local success, err = pcall(function()
randomHumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(PageInstance[math.random(#PageInstance)].Id)
end)
if randomHumanoidDescription then
vanChar.Humanoid:ApplyDescription(randomHumanoidDescription)
else
warn(err)
end
end