Join Friend System not Working

I am trying to make a gui that shows online friends in a certain game, and then has a join button that lets you join said friends.

The issue is that the spacing is all weird and wonky. I have no idea why.

Here is the issue in video:
robloxapp-20210518-1818181.wmv (1.1 MB)

Here is the code:

local Template = script.Template
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local currentPosition = UDim2.new(0,0,0,0)
local TeleportService = game:GetService("TeleportService")

local function cloneObject(object, Parent)
	local clonedObject = object:Clone()
	clonedObject.Parent = Parent
	return clonedObject
end

for i,v in pairs(LocalPlayer:GetFriendsOnline()) do  
	if v.PlaceId == 6830004489 then
	local FriendImage = cloneObject(Template, script.Parent)
	FriendImage.Position = currentPosition
	FriendImage.Name = v.UserName
	FriendImage.Username.Text = v.UserName
	if v.LastLocation then
		FriendImage.JoinButton.MouseButton1Click:Connect(function()
			print(v.GameId, v.PlaceId)
				TeleportService:TeleportToPlaceInstance(v.PlaceId, v.VisitorId, LocalPlayer)
			end)
			end
	end

	currentPosition = currentPosition + UDim2.new(0,0,0,50)
end
4 Likes

Did you forget the d? It should be

local FriendImage = clonedObject(Template, script.Parent)
1 Like

I figured out the solution.

Above

You need to add

if v.PlaceId == 6830004489 then

So the full script is:

local Template = script.Template
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local currentPosition = UDim2.new(0,0,0,0)
local TeleportService = game:GetService("TeleportService")

local function cloneObject(object, Parent)
	local clonedObject = object:Clone()
	clonedObject.Parent = Parent
	return clonedObject
end

for i,v in pairs(LocalPlayer:GetFriendsOnline()) do  
	if v.PlaceId == 6830004489 then
	local FriendImage = cloneObject(Template, script.Parent)
	FriendImage.Position = currentPosition
	FriendImage.Name = v.UserName
	FriendImage.Username.Text = v.UserName
	if v.LastLocation then
		FriendImage.JoinButton.MouseButton1Click:Connect(function()
			print(v.GameId, v.PlaceId)
				TeleportService:TeleportToPlaceInstance(v.PlaceId, v.VisitorId, LocalPlayer)
			end)
			end
	end
  if v.PlaceId == 6830004489 then
	currentPosition = currentPosition + UDim2.new(0,0,0,50)
end
end

No it should not. It is meant to do the function called cloneObject . Not reference the local variable there.

It calls this function.