I want people to be able to join their freinds’ server in-game. I obviously need to check that the friends’ GameId is the same as game.GameId (I need to teleport one player to one their online friends, that are Inside one of the places in the universe). However, it wasn’t working. So, I decided to print it, and then print game.GameId, and I get this:
This is the printing code:
And here’s my entire script if you’d like to take a look at it.
local Player = game.Players.LocalPlayer
local GuiBar = game:WaitForChild("ReplicatedStorage"):WaitForChild("Bar")
local TeleportService = game:GetService("TeleportService")
local function UpdateFriendList()
for _, bar in ipairs(script.Parent:GetChildren()) do
if bar:IsA("Frame") and bar.Name ~= "Template" then
bar:Destroy()
end
end
local Friends = Player:GetFriendsOnline()
for i, v in pairs(Friends) do
print(v.GameId)
print(game.GameId)
if v.GameId == game.GameId then
local NewBar = GuiBar:Clone()
NewBar:WaitForChild("DisplayName").Text = v.DisplayName
NewBar:WaitForChild("Username").Text = "@" .. v.UserName
NewBar:WaitForChild("AvatarImage").Image = game.Players:GetUserThumbnailAsync(v.VisitorId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
NewBar.Parent = script.Parent
if v.LastLocation then
NewBar:WaitForChild("MapText").Text = v.LastLocation
local JoinButton = NewBar:WaitForChild("JoinButton")
JoinButton.Activated:Connect(function()
TeleportService:TeleportToPlaceInstance(v.PlaceId, v.GameId, Player)
end)
end
end
end
end
while wait(5) do
UpdateFriendList()
end
P.S. this works great if you remove the game.GameId check.
P.P.S. when it updates the player list if flickers for a second before it can get the playing players. If you have a simple fix please tell me!
What I do is have a placeIdTable that holds all the place Ids for the game (will have to manually get all the place ids). Then check if the friend is in one of those place ids, and if true they can teleport to the game place.
Example:
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local onlineFriends = Players.LocalPlayer:GetFriendsOnline()
--All your game places
local placeIdTable = {
[9365621943] = true,
[9365638104] = true,
[9911069388] = true,
}
for _, friend in onlineFriends do
if placeIdTable[friend.PlaceId] then
local success, error = pcall(function()
TeleportService:TeleportToPlaceInstance(friend.PlaceId, friend.GameId, Players.LocalPlayer) --Teleport here
end)
if not success then
warn(error) --handle teleport errors here
end
end
end
Sadly, this didn’t work. However you’re right-- I can use PlaceId. I found that I could make a table with all of the whitelisted places and use that to check if you can join them. I wish there was a less complicated way to do this.