Add Friend GUI when a player clicked

Hello! I’ve been trying to figure out a way so that when a player clicks on another player, it gives them the option to send them a friend request. I’ve seen this feature implemented in games like Roblox High School 2. And I was wondering if I could make something like this myself for my own games. I’m not the best with scripting so any help on how to achieve this would be appreciated!

Thanks in advance!

1 Like

The friend system on those games is a completely different system than the normal roblox friend systems.

Believe it not, Roblox implemented a system for this, surprisingly. I just tested it out and it does in fact work.

It’s been covered by @BenSBk in this post:

If you need help with the implementation of this feature, let me know. I can help you out.

Help would be greatly appreciated, thanks!

Here’s a simple script that demonstrates this in implementation. I’ve added some comments to help you understand how it works.

Also, make sure this is in a LocalScript (not a normal Script) that is in StarterPack.

local Players = game:GetService("Players") --Players service
local StarterGui = game:GetService("StarterGui") --StarterGui service

local player = Players.LocalPlayer --Client player

local mouse = player:GetMouse() --Mouse of client player

mouse.Button1Down:Connect(function() --When the left click button is pressed.....
	local target = mouse.Target --Save whatever part was clicked on in the 3D space into the target variable
	
	local clickedPlayer = Players:GetPlayerFromCharacter(target.Parent) or Players:GetPlayerFromCharacter(target.Parent.Parent) --Attempt to save clicked part's player in a variable
	if clickedPlayer and clickedPlayer ~= player then --If clicked part actually WAS a descendant of a player and it isn't the client player then
		StarterGui:SetCore("PromptSendFriendRequest", clickedPlayer) --Send the friend request
	end
end)

Thanks for the help and the feedback!

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