Help with UserID

I’m not going to be on in a while so sorry if I don’t immediately respond :slight_smile:

So my goal with this script is to essentially set 2 rigs to two random friends of the player.
For some reason the game isn’t recognizing that the UserId is part of the player. I’m pretty sure its because I have to wait for the player to be found or something along those lines but I’m not sure.

Normal Script btw:

local desendants = script.Parent:GetDescendants()
local player



game.Teams["Vorld Wision"].PlayerAdded:Connect(function(plr)
	player = plr
	print(player.UserId)
end)
	
local Char1 = script.Parent.Rig1
local Char2 = script.Parent.Rig2

local pageInst = player:GetFriendsAsync(player.UserId)

local function iterPageItems(pages)
	return coroutine.wrap(function()
		local pagenum = 1
		while true do
			for _, item in ipairs(pages:GetCurrentPage()) do
				coroutine.yield(item, pagenum)
			end
			if pages.IsFinished then
				break
			end
			pages:AdvanceToNextPageAsync()
			pagenum = pagenum + 1
		end
	end)
end

local users = {}
for item, _pageNo in iterPageItems(pageInst) do
	table.insert(users, item.Username)
end


local function randmFriend()
	local rdnm = math.random(1, #users)
	local person = users[rdnm]
	return person
	end


function getParts()
	for _, v in pairs(desendants) do
		if v:IsA("Part") then
			v.Transparency = 0
			v.CanCollide = true
			v.CanTouch = true
		else if v:IsA("MeshPart") then
				v.Transparency = 0
				v.CanCollide = true
				v.CanTouch = true
		end	
			
		end
	end
end

Char1.Humanoid.HumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(game.Players:GetUserIdFromNameAsync(randmFriend()))   
Char2.Humanoid.HumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(game.Players:GetUserIdFromNameAsync(randmFriend()))
1 Like

It would be nice if you could share the error that is outputted when this script runs.

1 Like

Good day sir, I want to know what is going inside your mind right now. Please reply fast as I want the answer urgently.

This is going offtopic, check your messages, I’m messaging there.

The simple matter is that we are asynchronous in relation to the thread, but in the end, we are just RBLXScriptConnections firing before the instance is updated. If you look at it like that… the difference between us and the thread is like the difference between the mean of sums and the sum of means. It is clear that perchance merfacht buddy has failed to while not player do task.wait() end.

sorry man I was out for a day here is the error:
Workspace.UL.CargoContainer.Tables.Script:17: attempt to index nil with 'UserId'

I just tried adding this in above the pageInst, unfortunetly it gives me this error
GetFriendsAsync is not a valid member of Player "Players.lexsan82"

Update: I did fix that error but now I’m getting this one :frowning:
HumanoidDescription is not a valid member of Humanoid "Workspace.UL.CargoContainer.Tables.Rig1.Humanoid"

I fixed it.
#1 Issue with the first part you add : while not player do task.wait() end . above the pageInst variable line
#2 that second error I was getting was because GetFriendsAsync must be after game.players
#3 I was having trouble with that bottom line with applying the humanoid description. However, I discovered that the only way to apply a humanoid description is by using the ApplyDescription() function

Here is the entire new script:

local desendants = script.Parent:GetDescendants()
local player



game.Teams["Vorld Wision"].PlayerAdded:Connect(function(plr)
	player = plr
	print(player.UserId)
end)
	

	

local Char1 = script.Parent.Rig1
local Char2 = script.Parent.Rig2

while not player do task.wait() end
local pageInst = game.Players:GetFriendsAsync(player.UserId)

local function iterPageItems(pages)
	return coroutine.wrap(function()
		local pagenum = 1
		while true do
			for _, item in ipairs(pages:GetCurrentPage()) do
				coroutine.yield(item, pagenum)
			end
			if pages.IsFinished then
				break
			end
			pages:AdvanceToNextPageAsync()
			pagenum = pagenum + 1
		end
	end)
end

local users = {}
for item, _pageNo in iterPageItems(pageInst) do
	table.insert(users, item.Username)
end


local function randmFriend()
	local rdnm = math.random(1, #users)
	local person = users[rdnm]
	return person
	end


function getPartsAppear(model)
	for _, v in pairs(model:GetDescendants()) do
		if v:IsA("Part") then
			v.Transparency = 1
			v.CanCollide = false
			v.CanTouch = false
		else if v:IsA("MeshPart") then
				v.Transparency = 1
				v.CanCollide = false
				v.CanTouch = false
		end	
			
		end
	end
end

print(randmFriend())
print(randmFriend())
Char1.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(game.Players:GetUserIdFromNameAsync(randmFriend()))) 
Char2.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(game.Players:GetUserIdFromNameAsync(randmFriend()))) 
getPartsAppear(Char1)
getPartsAppear(Char2)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.