Can i make this script local?

Hello!

I am trying to load the players friends locally, show it shows the players friends for them only and other players friends different. but im struggling how

Here is the script i have (thanks to @NemPaws)

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)

	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

SpawnAllFriends(369951478) -- Your userId here

i would like the userID to be the players so it shows their friends and not the other player’s

– ScxiptedShark

1 Like

Isn’t this already able to be local?

The only change I can think of is using :WaitForChild() when you’re accessing stuff inside Workspace.

1 Like

i can try it, but i have seen other people get the error “can only be called by the backend server”

Try running it anyway and see if any errors pop up, alongside the line where it occurs.

My guess is that the Players:GetFriendsAsync() is server-only, but I don’t know why it would be limited to that.

1 Like

Yeah, i get this error:

Could not spawn 67227137’s character because: Humanoid::ApplyDescription() can only be called by the backend server

Couldn’t i do this with remote events tho? with .OnClientEvent?

Humanoid:ApplyDescription() can only be used on server-side.

I would try making a blank HumanoidDescription, using Instance.new(instance, parentTo), and then setting the humanoid’s description using that description you just made.

I would see why this is limited to server-side, so I would have to make this on the server, or from the client using a remote event.

So like this:

local NewRig = game.Players:CreateHumanoidFromCharacterDescription(game.Players.LocalPlayer, workspace)

I’ll try doing that, but if it doesn’t work, then we’ll both know that this can’t be on a client script.

1 Like

I Doubt it will work. I Do have another script but its really difficult to get it to do what i want. Can you help me out with that?

If you have a separate issue you need to create another forum post in Scripting Support.

If this current issue has been left unsolved, then you can now close it, as what you want to do can’t be possible; it has to be on a server script.

1 Like

Alright, i will do that! Thanks