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!
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)