---------------
--// Functions
---------------

local function resetGUI()
	for i,v in pairs(script.Parent:GetChildren()) do
		if v:IsA("Frame") and v.Name ~= "Template" and v.Name ~= "A" then
			v:Destroy()
		end
	end
end 

local function loadGUI(plr)
	for i,v in pairs(Players:GetPlayers()) do
		local clone = script.Parent.Template:Clone()
		clone.Parent = script.Parent
		clone.Name = ""
		clone.ImageLabel.Image = "rbxthumb://type=AvatarHeadShot&id="..plr.UserId.."&w=150&h=150"
		clone.Usernaame.Text = v.Name
		clone.TextButton.MouseButton1Down:Connect(function()
			if debounce == false then
				debounce = true
				local plot = workspace.Plots.Plot:FindFirstChild("Plot"..plr:GetAttribute("Plot"))
				local tween = TweenService:Create(LocalPlayer.Character.HumanoidRootPart, TweenInfo.new(.1), {["CFrame"] = plot.Pos.CFrame, })
				tween:Play()
				tween.Completed:Wait()
				task.wait(.5)
				debounce = false
			end
		end)
	end
end


local function updateGUI()
	resetGUI()
	loadGUI()
end


