Help make Join a friend gui only shows for a certain game

Hello, i have a join a friend script and im trying to make it where The gui to join them only appears if there playing a certain game so a certain GameId, rn its for every game.

local Player = game.Players.LocalPlayer
local Friends = Player:GetFriendsOnline(10)
local Temp = game.ReplicatedStorage.Template
local TPS = game:GetService("TeleportService")

for i,v in pairs(Friends) do
	local NewFrame = Temp:Clone()
	NewFrame.PlayerName.Text = v.UserName
	NewFrame.Parent = script.Parent.ScreenGui.Frame.ScrollingFrame
	NewFrame.PlayerImage.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=150&Format=Png&username="..v.UserName
	if v.LastLocation then
		NewFrame.GameName.Text = v.LastLocation
		NewFrame.Join.MouseButton1Down:Connect(function()
			TPS:TeleportToPlaceInstance(v.PlaceId, v.UserName, Player)
		end)
	end
end
1 Like

what exactly do you need to accomplish?

Right now it gives you the option to join anybody who’s playing a roblox game and any game, im trying to make it where the frame to join only gets cloned if there playing a certain game which is my game

So basically a join a friends lobby but this one is to join any lobby so I need to make it where it only clones for certain games your friend is playing

local UniverseId = game.GameId --universe id of current place
if v.LastLocation and v.GameId == UniverseId then 
	--code here only applies for places which belong in this game
end

do i do


local UniverseId = game.GameId.232213123123

or


local UniverseId = 1232312131

random Numbers are place id

Do not change it, game.GameId is a property itself, just like game.Name.

so how do i put the game id i want to use to make it where the gui only shows if its the correct id

You don’t need to. Simply keep it as it is and run it:

local Player = game.Players.LocalPlayer
local Friends = Player:GetFriendsOnline(10)
local Temp = game.ReplicatedStorage.Template
local TPS = game:GetService("TeleportService")

for i,v in pairs(Friends) do
	if v.GameId ~= game.GameId then continue end --skip current frame
	local NewFrame = Temp:Clone()
	NewFrame.PlayerName.Text = v.UserName
	NewFrame.Parent = script.Parent.ScreenGui.Frame.ScrollingFrame
	NewFrame.PlayerImage.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=150&Format=Png&username="..v.UserName
	if v.LastLocation then
		NewFrame.GameName.Text = v.LastLocation
		NewFrame.Join.MouseButton1Down:Connect(function()
			TPS:TeleportToPlaceInstance(v.PlaceId, v.UserName, Player)
		end)
	end
end
1 Like

local Is used for variables. For example if you make a code

local UniverseId = 39405245

Then variable can be used for

game.GameId = UniverseId

This is kinda what I want, even if there not playing my game the template gui is still gonna get cloned and show them playing a game I want it only to clone if it’s my game

This is exactly what it does, from now on I wont reply because it’s pointless.

No? It only changes the text of the text button if it’s my game. It’s still gonna get cloned because your not checking for it to be my game on line 7.

Yep I just checked it and your wrong, All it does is Change the text to my games name.

Fixed it, now it should work as intended.

how would i make it PlaceId, im testing it in another game rn


local Player = game.Players.LocalPlayer
local Friends = Player:GetFriendsOnline(10)
local Temp = game.ReplicatedStorage.Template
local TPS = game:GetService("TeleportService")

for i,v in pairs(Friends) do
	if v.GameId == 6803595647 then
		local NewFrame = Temp:Clone()
		NewFrame.PlayerName.Text = v.UserName
		NewFrame.Parent = script.Parent.ScreenGui.Frame.ScrollingFrame
		NewFrame.PlayerImage.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=150&Format=Png&username="..v.UserName
		if v.LastLocation then
			NewFrame.GameName.Text = v.LastLocation
			NewFrame.Join.MouseButton1Down:Connect(function()
				TPS:TeleportToPlaceInstance(v.PlaceId, v.UserName, Player)
			end)
		end
	end
end

i tried this but dident work…

Of course it didn’t because you have to copy exactly what I posted above, if you keep applying changes it wont work(if I didn’t make it clear the first 5 times I told you).

I changed the script and now it should work as you want it. All you have to do is change the Id to the type of game you want the player to teleport to.

Here’s the script:

local Player = game.Players.LocalPlayer
local Friends = Player:GetFriendsOnline(10)
local Temp = game.ReplicatedStorage.Template
local TPS = game:GetService("TeleportService")

local currentPosition = UDim2.new(0.06,0,0,25) -- You can adjust the position

for i,v in pairs(Friends) do
	if v.PlaceId == [GAME ID} then
		local userId = v.VisitorId
		local thumbType = Enum.ThumbnailType.HeadShot
		local thumbSize = Enum.ThumbnailSize.Size420x420
		local content, isReady = game.Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
			
		local NewFrame = Temp:Clone()
		NewFrame.PlayerName.Text = v.UserName
		NewFrame.Parent = script.Parent.Parent.Parent.JoinFriendFrame
		NewFrame.PlayerImage.Image = content --"http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=150&Format=Png&username="..v.UserName
		NewFrame.Position = currentPosition
		local GetName = game:GetService("MarketplaceService"):GetProductInfo(v.PlaceId)
	    if v.LastLocation then
			NewFrame.GameName.Text = GetName.Name
			NewFrame.Join.MouseButton1Down:Connect(function()
				TPS:TeleportToPlaceInstance(v.PlaceId, v.GameId, Player)
			end)
		end
		currentPosition = currentPosition + UDim2.new(0,0,0,150)
	end
end