How would I achieve this?

Hello, So last night I had a idea where in a game there is a UI that when pressed/clicked Opens a ScreenGUI and in it there are buttons but you might ask what are so special about these buttons?
Well these buttons are labelled with the players friends and when pressed/clicked changes the player into the friend that they picked.
I was wondering how would I manage to do this because I would need to make it add buttons depending on the amount of friends they have.

Any help on how I would do this is very appreciated.

If you want to get only the OnlineFriends, you might want to use this -
GetFriendsOnline

If you want to get all the player’ friends, then you might want to use this -
GetFriendsAsync

2 Likes

So basically you want to load up a player’s friend list and each button being a friend if they click on one of their friends via button they transform into them?

1 Like

No, I think he means if you click on a button, your avatar will turn into that friend’s avatar - basically a morphing system.

1 Like

You can achieve this by using a ScrollingFrame and formatting 1 TextButton inside of the ScrollingFrame and then put it somewhere else, for example, [ReplicatedStorage],(ReplicatedStorage | Roblox Creator Documentation) and make a script that goes through the Friends list and retrieves the button from ReplicatedStorage and clones it x times (x is how many friends there are). For every clone, parent it to the ScrollingFrame and change the name to the text name of the friend.

If you need help making the script, let me know and I can help you.

1 Like

You could use a UIListLayout along with a ScrollingFrame. Just clone an example button template for each friend in their friends list and parent it to the ScrollingFrame.

1 Like

You are correct.
Do you know any way I could achieve this?

Thanks.
If it’s not a pain could you help me a bit with the script as I’ve never really used scripts to get players freinds.

1 Like

Sure thing! How can I help you?

Thanks, All I need help with is when the player presses/clicks the button they change into there freinds avatar.
I believe I can do the buttons showing and appearing with the players freinds usernames but I might struggle.

1 Like

Give me about like 15 minutes ish :slight_smile:

image

Script:

local Players = game:GetService("Players")

local event = game:GetService("ReplicatedStorage"):FindFirstChild("AvatarChange")

event.OnServerEvent:Connect(function(player,userid)
	
	local description = Players:GetHumanoidDescriptionFromUserId(userid)
	
	player.Character:FindFirstChild("Humanoid"):ApplyDescription(description)
	
end)

LocalScript:

local button = script.Parent

local event = game:GetService("ReplicatedStorage"):FindFirstChild("AvatarChange")

button.MouseButton1Click:Connect(function(player)
	
	local userid = button:GetAttribute("UserId")
	
	event:FireServer(userid)
	
end)

Btw there is a Attribute in the TextButton called UserId. When you clone for each friend, set that attribute to that friend’s userid

Hope this helps!

1 Like

Everything you saw can be found in this model:

(please tell me if it is offsale)

1 Like

It is offsale thanks, This will help me a lot.
If I do run into a problem with the adding UI buttons is it ok if I ask you to help me a bit.

1 Like

You should be able to click Get and get it for free if you need it