Does anyone know how I can make these friend joining scripts work, they’re supposed to clone a textbutton to display a player(which works) and search all friends for being able to join them within a server to a game I’m working on. (let me know if more info is needed)
Errors:
and in game it says that the place is restricted.
Main script (local):
while wait(10) do
local chil = script.Parent.Parent:GetChildren()
for i = 1, #chil do
if chil[i].Name =="FriendDisplay" then
chil[i]:Destroy()
end
end
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local USERNAME = game.Players.LocalPlayer.Name
local function iterPageItems(pages)
return coroutine.wrap(function()
local pagenum = 1
while true do
for _, item in ipairs(pages:GetCurrentPage()) do
coroutine.yield(item, pagenum)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
pagenum = pagenum + 1
end
end)
end
-- First, get the user ID of the player
local userId = Players:GetUserIdFromNameAsync(USERNAME)
-- Then, get a FriendPages object for their friends
local friendPages = Players:GetFriendsAsync(userId)
-- Iterate over the items in the pages. For FriendPages, these
-- are tables of information about the friend, including Username.
-- Collect each username in a table
local usernames = {}
for item, _pageNo in iterPageItems(friendPages) do
if item.IsOnline == true then
local friendUI = script.Parent:Clone()
friendUI.Name = "FriendDisplay"
friendUI.LocalScript.Enabled = false
friendUI.Visible = true
friendUI.Text = item.Username
friendUI.Parent = script.Parent.Parent
script.Parent.RemoteEvent:FireServer(item.Id) script.Parent.RemoteEvent.OnClientEvent:Connect(function(TP)
friendUI.TextButton.MouseButton1Click:Connect(function()
TeleportService:TeleportToPlaceInstance(15589675015 , TP)
end)
end)
table.insert(usernames, item.Username)
end
end
end
Server search script (for finding the friends, btw it’s a Server script):
local TeleportService = game:GetService("TeleportService")
script.Parent.RemoteEvent.OnServerEvent:Connect(function(ply,item)
local TP = TeleportService:GetPlayerPlaceInstanceAsync(item)
script.Parent.RemoteEvent:FireAllClients(TP)
end)