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

Followed Alert

Followed Alert

Oct 01 2018, 2:43 AM PST

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)