[SOLVED] GameId returns hash for some reason

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:
Screen Shot 2023-05-30 at 6.29.06 PM

This is the printing code:
Screen Shot 2023-05-30 at 6.32.28 PM

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!


Thank you for any help!

I saw there’s a line:

if friend["GameId"] == game.JobId then

Hope it will help

Also the PlaceId returns an Id you are probably looking for, not GameId

2 Likes

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
2 Likes

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.

2 Likes

What does the = true do in the table?

Oh it’s just so I can use placeIdTable as a lookup table and don’t have to for loop through it to find the value

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.