PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

FollowUserId

Player

int64

The FollowUserId is a Player property that contains the Player/UserId of the user that a player followed into the game. If the player did not follow anyone into the game, this property will be 0. This property is useful for alerting players who have been followed by another player into the game.

You can get the name of the player followed using this user ID and the Players/GetNameFromUserIdAsync function.


Code Samples


Followed Alert

This code sample alerts players if a new player follows the local player into the game. It does so using a Hint. Place this in a LocalScript in StarterPlayerScripts.

local Players = game.GetService("Players")
local Debris = game:GetService("Debris")
local player = Players.LocalPlayer

local function onPlayerAdded(newPlayer)
	if newPlayer.FollowUserId == player.UserId then
		local hint = Instance.new("Hint")
		hint.Parent = player:WaitForChild("PlayerGui")
		hint.Text = "You were followed to this game by " .. newPlayer.Name .. "!"
		Debris:AddItem(hint, 3)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)