Question about making a send friend request button

Hi there, I want to know how I would go about making my own send friend request button for a custom leaderboard I’ve made. There is absolutely nothing about this from what I can see on DevHub and YouTube, however I know that this does exist, a couple of games like @Wsly’s Deathrun have implemented this.

Screenshot:

Code:

	local lib = game.Players:GetChildren()
for i, v in ipairs(lib) do
	script.Parent.CanvasSize = UDim2.new(0, 0, 0, script.Parent.CanvasSize.Y.Offset + 40)
	local obj = game.ReplicatedStorage.Template:Clone()
		obj.Parent = script.Parent
		obj.Visible = true
		obj.Name = "@"..v.Name
	obj.TextLabel.Text = "@"..v.Name
	local userid = v.UserId
	local thumbtype = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size420x420
	local content, isReady = game.Players:GetUserThumbnailAsync(userid, thumbtype, thumbSize)
	obj.ImageLabel.Image = content
	end

game.Players.PlayerAdded:Connect(function(player)
	wait(0.5)
	script.Parent.CanvasSize = UDim2.new(0, 0, 0, script.Parent.CanvasSize.Y.Offset + 40)
	local obj = game.ReplicatedStorage.Template:Clone()
	obj.Parent = script.Parent
	obj.Visible = true
	obj.Name = "@"..player.Name
	obj.TextLabel.Text = "@"..player.Name
	local userid = player.UserId
	local thumbtype = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size420x420
	local content, isReady = game.Players:GetUserThumbnailAsync(userid, thumbtype, thumbSize)
	obj.ImageLabel.Image = content
end)

game.Players.PlayerRemoving:Connect(function(player)
	script.Parent.CanvasSize = UDim2.new(0, 0, 0, script.Parent.CanvasSize.Y.Offset - 40)
	
	local par = script.Parent
	local name = "@"..player.Name
	
	local object = par:FindFirstChild(name)
	object:Destroy()
end)

Thanks in advance!

First, make every player leaderboard object a button, and when a new player joins, connect it to an event. Inside the event, check if the player clicking is the same player that joined, if so, you have a choice of doing nothing or displaying a different menu since you cant friend yourself. if it’s not the same player, open a new menu with an add/remove friend button. also use this event to add to a datastore

I don’t think you’re understanding, I have classconverted the text to a button (however not for the image yet), I just want to know what event I’m supposed to fire since I can’t see any information on it

For example, DevHub shows nothing about firing a friend request in the documentation for FriendsService

Edit: I was told it was a PlayersService event but I can’t find anything in that either.

See here:
New SetCore Methods for prompting social actions - Updates / Announcements - DevForum | Roblox

2 Likes

You can also use the In-experience Profile Developer Module that Roblox provided for us recently.

The Module provides us with a Send Request feature along with other bonuses.

Just one thing if you use it: It creates hundreds of false Script Analysis errors. So be prepared for that.

1 Like